home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / vibrant / ncbidraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  113.4 KB  |  4,861 lines  |  [TEXT/R*ch]

  1. /*   ncbidraw.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  ncbidraw.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   1/1/91
  31. *
  32. * $Revision: 2.20 $
  33. *
  34. * File Description: 
  35. *       Vibrant drawing functions.
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46.  
  47. #include <ncbi.h>
  48. #include <ncbidraw.h>
  49. #include <ncbiwin.h>
  50. #include <ncbiport.h>
  51.  
  52. #ifdef VAR_ARGS
  53. #include <varargs.h>
  54. #else
  55. #include <stdarg.h>
  56. #endif
  57.  
  58. Nlm_Boolean  Nlm_nowPrinting = FALSE;
  59.  
  60. #ifdef WIN_MAC
  61. RGBColor  Nlm_RGBforeColor;
  62. RGBColor  Nlm_RGBbackColor;
  63. #endif
  64.  
  65. #ifdef WIN_MSWIN
  66. HWND         Nlm_currentHWnd;
  67. HDC          Nlm_currentHDC;
  68. #endif
  69.  
  70. #ifdef WIN_X
  71. Display      *Nlm_currentXDisplay;
  72. int          Nlm_currentXScreen;
  73. Window       Nlm_currentXWindow;
  74. GC           Nlm_currentXGC;
  75. Nlm_Uint4    Nlm_XbackColor;
  76. Nlm_Uint4    Nlm_XforeColor;
  77. Nlm_Int2     Nlm_XOffset;
  78. Nlm_Int2     Nlm_YOffset;
  79. Nlm_RegioN   Nlm_clpRgn;
  80. #endif
  81.  
  82. Nlm_RegioN   Nlm_updateRgn;
  83. Nlm_RecT     Nlm_updateRect;
  84.  
  85. Nlm_Int2     Nlm_stdAscent;
  86. Nlm_Int2     Nlm_stdDescent;
  87. Nlm_Int2     Nlm_stdLeading;
  88. Nlm_Int2     Nlm_stdFontHeight;
  89. Nlm_Int2     Nlm_stdLineHeight;
  90. Nlm_Int2     Nlm_stdCharWidth;
  91.  
  92. Nlm_FonT     Nlm_systemFont = NULL;
  93. Nlm_FonT     Nlm_programFont = NULL;
  94.  
  95. #define COPY_MODE   1
  96. #define MERGE_MODE  2
  97. #define INVERT_MODE 3
  98. #define ERASE_MODE  4
  99.  
  100. static Nlm_Int2    currentMode = COPY_MODE;
  101.  
  102. static Nlm_FonT    Nlm_fontList = NULL;
  103. #ifndef DCLAP
  104. static 
  105. #endif
  106. Nlm_FonT    Nlm_fontInUse = NULL;
  107.  
  108. static Nlm_RegioN  Nlm_scrollRgn;
  109.  
  110. #ifdef WIN_MAC
  111. static Nlm_Byte  whitePat [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  112. static Nlm_Byte  ltGrayPat [] = {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22};
  113. static Nlm_Byte  grayPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  114. static Nlm_Byte  dkGrayPat [] = {0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD};
  115. static Nlm_Byte  blackPat [] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  116.  
  117. static Nlm_Byte  dotPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  118. static Nlm_Byte  dashPat [] = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
  119.  
  120. static Nlm_Boolean  hasColorQD = FALSE;
  121. #endif
  122.  
  123. #ifdef WIN_MSWIN
  124. static Nlm_Int2    currentPenStyle = PS_SOLID;
  125. static Nlm_Int2    currentPenWidth = 1;
  126. static void        *currentPattern = NULL;
  127.  
  128. static COLORREF    blackColor;
  129. static COLORREF    redColor;
  130. static COLORREF    greenColor;
  131. static COLORREF    blueColor;
  132. static COLORREF    cyanColor;
  133. static COLORREF    magentaColor;
  134. static COLORREF    yellowColor;
  135. static COLORREF    whiteColor;
  136.  
  137. static Nlm_Uint2   blackPat [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  138. static Nlm_Uint2   dkGrayPat [] = {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22};
  139. static Nlm_Uint2   grayPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  140. static Nlm_Uint2   ltGrayPat [] = {0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD};
  141. static Nlm_Uint2   whitePat [] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  142.  
  143. static Nlm_Uint2   dotPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  144. static Nlm_Uint2   dashPat [] = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
  145.  
  146. static HPEN        hBlackPen;
  147. static HPEN        hNullPen;
  148. static HPEN        hWhitePen;
  149. static HBRUSH      hBlackBrush;
  150. static HBRUSH      hDkGrayBrush;
  151. static HBRUSH      hGrayBrush;
  152. static HBRUSH      hHollowBrush;
  153. static HBRUSH      hLtGrayBrush;
  154. static HBRUSH      hNullBrush;
  155. static HBRUSH      hWhiteBrush;
  156. static HFONT       hAnsiFixedFont;
  157. static HFONT       hAnsiVarFont;
  158. static HFONT       hDeviceDefaultFont;
  159. static HFONT       hOemFixedFont;
  160. static HFONT       hSystemFont;
  161. static HFONT       hSystemFixedFont;
  162.  
  163. static TEXTMETRIC  textMetrics;
  164. #endif
  165.  
  166. #ifdef WIN_X
  167. static XFontStruct  *currentFont;
  168. static Pixmap       currentPixmap = 0;
  169. static Nlm_PoinT    currentPoint;
  170. static Nlm_Uint4    currentBkColor;
  171. static Nlm_Uint4    currentFgColor;
  172. static int          currentFunction = GXcopy;
  173. static int          currentFillStyle = FillOpaqueStippled;
  174.  
  175. static Nlm_Uint4    blackColor;
  176. static Nlm_Uint4    redColor;
  177. static Nlm_Uint4    greenColor;
  178. static Nlm_Uint4    blueColor;
  179. static Nlm_Uint4    cyanColor;
  180. static Nlm_Uint4    magentaColor;
  181. static Nlm_Uint4    yellowColor;
  182. static Nlm_Uint4    whiteColor;
  183.  
  184. static Nlm_Uint1    whitePat [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  185. static Nlm_Uint1    ltGrayPat [] = {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22};
  186. static Nlm_Uint1    grayPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  187. static Nlm_Uint1    dkGrayPat [] = {0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD};
  188. static Nlm_Uint1    blackPat [] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  189.  
  190. static Nlm_Uint1    dotPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  191. static Nlm_Uint1    dashPat [] = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
  192.  
  193. static XFontStruct  fontInfo;
  194. static Nlm_Uint1    flip [256];
  195.  
  196. static Nlm_Boolean  hasColor;
  197. static Nlm_RgnTool  emptyRgn;
  198. #endif
  199.  
  200. #ifdef WIN_MAC
  201. extern  void  Nlm_SetPort (GrafPtr grafptr)
  202.  
  203. {
  204.   SetPort (grafptr);
  205. }
  206. #endif
  207.  
  208. #ifdef WIN_MSWIN
  209. extern  void  Nlm_SetPort (HWND hwnd, HDC hdc)
  210.  
  211. {
  212.   Nlm_currentHWnd = hwnd;
  213.   Nlm_currentHDC = hdc;
  214. }
  215. #endif
  216.  
  217. #ifdef WIN_X
  218. extern  void  Nlm_SetPort (Window window, GC gc)
  219.  
  220. {
  221.   Nlm_currentXWindow = window;
  222.   Nlm_currentXGC = gc;
  223. }
  224.  
  225. /* for internal Vibrant use only */
  226. extern  XFontStruct * Nlm_XLoadQueryFont (Display *d, Nlm_CharPtr fDescr, Nlm_Boolean critical)
  227. {
  228.   XFontStruct *f;
  229.  
  230.   if ((f = XLoadQueryFont(d, fDescr)) == NULL && critical)
  231.   {
  232.     fprintf (stderr, "Vibrant: Unable to load critical font <%s>\n", fDescr);
  233.     exit (1);
  234.   }
  235.  
  236.   return f;
  237. }
  238.  
  239. #endif
  240.  
  241. static void Nlm_LoadFontData (Nlm_FonT f, Nlm_FonT nxt,
  242.                               Nlm_CharPtr nam, Nlm_Int2 siz,
  243.                               Nlm_Int2 scl, Nlm_Boolean bld,
  244.                               Nlm_Boolean itl, Nlm_Boolean und,
  245.                               Nlm_Int2 num, Nlm_Int2 stl,
  246.                               Nlm_FontTool hdl, Nlm_FonT prnt)
  247.  
  248. {
  249.   Nlm_FntPtr  fp;
  250.  
  251.   if (f != NULL) {
  252.     fp = (Nlm_FntPtr) Nlm_HandLock (f);
  253.     fp->next = nxt;
  254.     Nlm_StringNCpy (fp->name, nam, sizeof (fp->name));
  255.     fp->size = siz;
  256.     fp->scale = scl;
  257.     fp->bld = bld;
  258.     fp->ital = itl;
  259.     fp->undlin = und;
  260.     fp->number = num;
  261.     fp->style = stl;
  262.     fp->handle = hdl;
  263.     fp->print = prnt;
  264.     Nlm_HandUnlock (f);
  265.   }
  266. }
  267.  
  268. static void Nlm_SetFontData (Nlm_FonT f, Nlm_FontData * fdata)
  269.  
  270. {
  271.   Nlm_FntPtr  fp;
  272.  
  273.   if (f != NULL && fdata != NULL) {
  274.     fp = (Nlm_FntPtr) Nlm_HandLock (f);
  275.     *fp = *fdata;
  276.     Nlm_HandUnlock (f);
  277.   }
  278. }
  279.  
  280. #ifdef DCLAP
  281. extern
  282. #else 
  283. static
  284. #endif
  285.  void Nlm_GetFontData (Nlm_FonT f, Nlm_FontData * fdata)
  286.  
  287. {
  288.   Nlm_FntPtr  fp;
  289.  
  290.   if (f != NULL && fdata != NULL) {
  291.     fp = (Nlm_FntPtr) Nlm_HandLock (f);
  292.     *fdata = *fp;
  293.     Nlm_HandUnlock (f);
  294.   }
  295. }
  296.  
  297. #ifdef WIN_MAC
  298. static void Nlm_ChooseColor (Nlm_Int4 color)
  299.  
  300. {
  301.   ForeColor (color);
  302. }
  303.  
  304. #endif
  305.  
  306. #ifdef WIN_MSWIN
  307. static Nlm_Boolean Nlm_NotAStockPen (HPEN pen)
  308.  
  309. {
  310.   return (Nlm_Boolean) (pen != hBlackPen && pen != hNullPen && pen != hWhitePen);
  311. }
  312.  
  313. static Nlm_Boolean Nlm_NotAStockBrush (HBRUSH brush)
  314.  
  315. {
  316.   return (Nlm_Boolean) (brush != hBlackBrush && brush != hDkGrayBrush &&
  317.                         brush != hGrayBrush && brush != hHollowBrush &&
  318.                         brush != hLtGrayBrush && hNullBrush &&
  319.                         brush != hWhiteBrush);
  320. }
  321.  
  322. static Nlm_Boolean Nlm_NotAStockFont (HFONT font)
  323.  
  324. {
  325.   return (Nlm_Boolean) (font != hAnsiFixedFont && font != hAnsiVarFont &&
  326.                         font != hDeviceDefaultFont && font != hOemFixedFont &&
  327.                         font != hSystemFont && font != hSystemFixedFont);
  328. }
  329.  
  330. static void Nlm_RecreateBrushes (void)
  331.  
  332. {
  333.   Nlm_Int4  color;
  334.   HBITMAP   hBitmap;
  335.   HBRUSH    newBrush;
  336.   HPEN      newPen;
  337.   HBRUSH    oldBrush;
  338.   HPEN      oldPen;
  339.  
  340.   if (Nlm_currentHDC != NULL) {
  341.     color = GetTextColor (Nlm_currentHDC);
  342.     newPen = CreatePen (currentPenStyle, currentPenWidth, color);
  343.     if (newPen != NULL) {
  344.       oldPen = SelectObject (Nlm_currentHDC, newPen);
  345.       if (Nlm_NotAStockPen (oldPen)) {
  346.         DeleteObject (oldPen);
  347.       }
  348.     }
  349.     if (currentPattern == NULL) {
  350.       currentPattern = whitePat;
  351.     }
  352.     hBitmap = CreateBitmap (8, 8, 1, 1, (LPSTR) currentPattern);
  353.     newBrush = CreatePatternBrush (hBitmap);
  354.     if (newBrush != NULL) {
  355.       oldBrush = SelectObject (Nlm_currentHDC, newBrush);
  356.       if (Nlm_NotAStockBrush (oldBrush)) {
  357.         DeleteObject (oldBrush);
  358.       }
  359.     }
  360.     DeleteObject (hBitmap);
  361.   }
  362. }
  363.  
  364. static void Nlm_SelectPattern (Nlm_Int2 style, Nlm_Int2 width, void * pat)
  365.  
  366. {
  367.   currentPenStyle = style;
  368.   currentPenWidth = width;
  369.   currentPattern = pat;
  370.   Nlm_RecreateBrushes ();
  371. }
  372.  
  373.  
  374.  
  375. static void Nlm_ChooseColor (Nlm_Int4 color)
  376.  
  377. {
  378.   if (Nlm_currentHDC != NULL) {
  379.     SetTextColor (Nlm_currentHDC, color);
  380.     Nlm_RecreateBrushes ();
  381.   }
  382. }
  383.  
  384. static Nlm_Boolean Nlm_GetTextMetrics (void)
  385.  
  386. {
  387.   HDC          hDC;
  388.   Nlm_Boolean  success;
  389.  
  390.   success = FALSE;
  391.   if (Nlm_currentHDC != NULL) {
  392.     success = (Nlm_Boolean) GetTextMetrics (Nlm_currentHDC, &textMetrics);
  393.   } else {
  394.     hDC = CreateIC ("DISPLAY", NULL, NULL, NULL);
  395.     success = (Nlm_Boolean) GetTextMetrics (hDC, &textMetrics);
  396.     DeleteDC (hDC);
  397.   }
  398.   return success;
  399. }
  400.  
  401. static HBRUSH GetBackgroundBrush (HWND hwnd)
  402.  
  403. {
  404. #if !defined(WIN32) && !defined(WIN32BOR)
  405.   return (HBRUSH) GetClassWord (hwnd, GCW_HBRBACKGROUND);
  406. #else
  407.   return (HBRUSH) GetClassLong (hwnd, GCL_HBRBACKGROUND);
  408. #endif
  409. }
  410. #endif
  411.  
  412. #ifdef WIN_X
  413. static void Nlm_SelectPattern (void * pat)
  414.  
  415. {
  416.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0) {
  417.     if (currentPixmap != 0) {
  418.       XFreePixmap (Nlm_currentXDisplay, currentPixmap);
  419.     }
  420.     currentPixmap = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  421.                                            (char *) pat, 8, 8);
  422.     if (currentPixmap != 0 && Nlm_currentXGC != NULL) {
  423.       XSetStipple (Nlm_currentXDisplay, Nlm_currentXGC, currentPixmap);
  424.     }
  425.   }
  426. }
  427.  
  428. static void Nlm_ChooseColor (Nlm_Uint4 color)
  429.  
  430. {
  431.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  432.     XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, color);
  433.     currentFgColor = color;
  434.   }
  435. }
  436.  
  437. static Nlm_Boolean Nlm_GetTextMetrics (void)
  438.  
  439. {
  440.   Nlm_Boolean  success;
  441.  
  442.   success = FALSE;
  443.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  444.     if (currentFont != NULL) {
  445.       fontInfo = *currentFont;
  446.       success = TRUE;
  447.     }
  448.   }
  449.   return success;
  450. }
  451. #endif
  452.  
  453.  
  454. #ifdef DCLAP
  455.  
  456. extern void Nlm_SelectBackColor (Nlm_Uint1 red, Nlm_Uint1 green, Nlm_Uint1 blue)
  457. {
  458. #ifdef WIN_MAC
  459.   RGBColor   color;
  460.   Nlm_Uint2  bl;
  461.   Nlm_Uint2  gn;
  462.   Nlm_Uint2  rd;
  463.  
  464.   if (hasColorQD) {
  465.     rd = (Nlm_Uint2) red;
  466.     gn = (Nlm_Uint2) green;
  467.     bl = (Nlm_Uint2) blue;
  468.     color.red = rd << 8;
  469.     color.green = gn << 8;
  470.     color.blue = bl << 8;
  471.     RGBBackColor (&color);
  472.       } 
  473.   else if ((int) red + (int) green + (int) blue < 192)  
  474.       BackColor (blackColor);
  475.   else  
  476.       BackColor (whiteColor);
  477.           
  478. #endif
  479. #ifdef WIN_MSWIN
  480.   COLORREF   color;
  481.   Nlm_Uint2  bl;
  482.   Nlm_Uint2  gn;
  483.   Nlm_Uint2  rd;
  484.  
  485.   rd = (Nlm_Uint2) red;
  486.   gn = (Nlm_Uint2) green;
  487.   bl = (Nlm_Uint2) blue;
  488.   color = RGB (rd, gn, bl);
  489.   if (Nlm_currentHDC != NULL) {
  490.     SetBkColor (Nlm_currentHDC, color);
  491.     Nlm_RecreateBrushes ();
  492.       }
  493. #endif
  494. #ifdef WIN_X
  495.   Colormap   colormap;
  496.   Nlm_Uint2  bl;
  497.   Nlm_Uint2  gn;
  498.   Nlm_Uint2  rd;
  499.   XColor     xcolor;
  500.  
  501.   if (Nlm_currentXDisplay == NULL || Nlm_currentXGC == NULL) 
  502.       return;
  503.   else if (hasColor) {
  504.     rd = (Nlm_Uint2) red;
  505.     gn = (Nlm_Uint2) green;
  506.     bl = (Nlm_Uint2) blue;
  507.     xcolor.red = rd << 8;
  508.     xcolor.green = gn << 8;
  509.     xcolor.blue = bl << 8;
  510.     if (Nlm_currentXDisplay != NULL) {
  511.       colormap = DefaultColormap (Nlm_currentXDisplay, Nlm_currentXScreen);
  512.       if (XAllocColor (Nlm_currentXDisplay, colormap, &xcolor) == 0) 
  513.         xcolor.pixel = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  514.         currentBkColor = xcolor.pixel;
  515.         }
  516.       } 
  517.   else if ((int) red + (int) green + (int) blue < 192) 
  518.     currentBkColor = blackColor;
  519.   else 
  520.     currentBkColor = whiteColor;
  521.     XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  522. #endif
  523. }
  524.  
  525. #endif /* DCLAP */
  526.  
  527.  
  528.  
  529. extern void Nlm_ResetDrawingTools (void)
  530.  
  531. {
  532. #ifdef WIN_MAC
  533.   PenNormal ();
  534.   PenMode (patCopy);
  535.   TextMode (srcOr);
  536.   if (hasColorQD) {
  537.     RGBForeColor (&Nlm_RGBforeColor);
  538.     RGBBackColor (&Nlm_RGBbackColor);
  539.   } else {
  540.     ForeColor (blackColor);
  541.     BackColor (whiteColor);
  542.   }
  543. #endif
  544. #ifdef WIN_MSWIN
  545.   HBRUSH  oldBrush;
  546.   HFONT   oldFont;
  547.   HPEN    oldPen;
  548.  
  549.   if (Nlm_currentHDC != NULL) {
  550.     SetROP2 (Nlm_currentHDC, R2_COPYPEN);
  551.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  552.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  553.     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (SYSTEM_FONT));
  554.     SetTextColor (Nlm_currentHDC, GetSysColor (COLOR_WINDOWTEXT));
  555.     SetBkColor (Nlm_currentHDC, GetSysColor (COLOR_WINDOW));
  556.     if (Nlm_NotAStockPen (oldPen)) {
  557.       DeleteObject (oldPen);
  558.     }
  559.     if (Nlm_NotAStockBrush (oldBrush)) {
  560.       DeleteObject (oldBrush);
  561.     }
  562.     Nlm_SelectPattern (PS_SOLID, 1, blackPat);
  563.   }
  564. #endif
  565. #ifdef WIN_X
  566.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  567.     currentMode = COPY_MODE;
  568.     currentFunction = GXcopy;
  569.     currentFillStyle = FillOpaqueStippled;
  570.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  571.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  572.     if (hasColor) {
  573.       XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, Nlm_XbackColor);
  574.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, Nlm_XforeColor);
  575.       currentBkColor = Nlm_XbackColor;
  576.       currentFgColor = Nlm_XforeColor;
  577.     } else {
  578.       XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, whiteColor);
  579.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, blackColor);
  580.       currentBkColor = whiteColor;
  581.       currentFgColor = blackColor;
  582.     }
  583.     XSetLineAttributes (Nlm_currentXDisplay, Nlm_currentXGC,
  584.                         1, LineSolid, CapButt, JoinMiter);
  585.     Nlm_SelectPattern (blackPat);
  586.   }
  587. #endif
  588.   currentMode = COPY_MODE;
  589. }
  590.  
  591. static void Nlm_PointToolToPoinT (Nlm_PointTool src, Nlm_PointPtr dst)
  592.  
  593. {
  594.   if (dst != NULL) {
  595. #ifdef WIN_MAC
  596.     dst->x = src.h;
  597.     dst->y = src.v;
  598. #endif
  599. #ifdef WIN_MSWIN
  600.     dst->x = (Nlm_Int2) src.x;
  601.     dst->y = (Nlm_Int2) src.y;
  602. #endif
  603. #ifdef WIN_X
  604.     dst->x = src.x;
  605.     dst->y = src.y;
  606. #endif
  607.   }
  608. }
  609.  
  610. static void Nlm_PoinTToPointTool (Nlm_PoinT src, Nlm_PointTool PNTR dst)
  611.  
  612. {
  613.   if (dst != NULL) {
  614. #ifdef WIN_MAC
  615.     dst->h = src.x;
  616.     dst->v = src.y;
  617. #endif
  618. #ifdef WIN_MSWIN
  619.     dst->x = src.x;
  620.     dst->y = src.y;
  621. #endif
  622. #ifdef WIN_X
  623.     dst->x = src.x;
  624.     dst->y = src.y;
  625. #endif
  626.   }
  627. }
  628.  
  629. static void Nlm_RectToolToRecT (Nlm_RectTool PNTR src, Nlm_RectPtr dst)
  630.  
  631. {
  632.   if (dst != NULL && src != NULL) {
  633. #ifdef WIN_MAC
  634.     dst->left = src->left;
  635.     dst->top = src->top;
  636.     dst->right = src->right;
  637.     dst->bottom = src->bottom;
  638. #endif
  639. #ifdef WIN_MSWIN
  640.     dst->left = (Nlm_Int2) src->left;
  641.     dst->top = (Nlm_Int2) src->top;
  642.     dst->right = (Nlm_Int2) src->right;
  643.     dst->bottom = (Nlm_Int2) src->bottom;
  644. #endif
  645. #ifdef WIN_X
  646.     dst->left = src->x;
  647.     dst->top = src->y;
  648.     dst->right = src->x + src->width;
  649.     dst->bottom = src->y + src->height;
  650. #endif
  651.   }
  652. }
  653.  
  654. static void Nlm_RecTToRectTool (Nlm_RectPtr src, Nlm_RectTool PNTR dst)
  655.  
  656. {
  657.   if (dst != NULL && src != NULL) {
  658. #ifdef WIN_MAC
  659.     dst->left = MIN (src->left, src->right);
  660.     dst->top = MIN (src->top, src->bottom);
  661.     dst->right = MAX (src->left, src->right);
  662.     dst->bottom = MAX (src->top, src->bottom);
  663. #endif
  664. #ifdef WIN_MSWIN
  665.     dst->left = MIN (src->left, src->right);
  666.     dst->top = MIN (src->top, src->bottom);
  667.     dst->right = MAX (src->left, src->right);
  668.     dst->bottom = MAX (src->top, src->bottom);
  669. #endif
  670. #ifdef WIN_X
  671.     dst->x = MIN (src->left, src->right);
  672.     dst->y = MIN (src->top, src->bottom);
  673.     dst->width = ABS (src->right - src->left);
  674.     dst->height = ABS (src->bottom - src->top);
  675. #endif
  676.   }
  677. }
  678.  
  679. static void Nlm_LocalToGlobal (Nlm_PointPtr pt)
  680.  
  681. {
  682. #ifdef WIN_MAC
  683.   Nlm_PointTool  ptool;
  684.  
  685.   if (pt != NULL) {
  686.     Nlm_PoinTToPointTool (*pt, &ptool);
  687.     LocalToGlobal (&ptool);
  688.     Nlm_PointToolToPoinT (ptool, pt);
  689.   }
  690. #endif
  691. #ifdef WIN_MSWIN
  692.   Nlm_PointTool  ptool;
  693.  
  694.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  695.     Nlm_PoinTToPointTool (*pt, &ptool);
  696.     ClientToScreen (Nlm_currentHWnd, &ptool);
  697.     Nlm_PointToolToPoinT (ptool, pt);
  698.   }
  699. #endif
  700. #ifdef WIN_X
  701. #endif
  702. }
  703.  
  704. static void Nlm_GlobalToLocal (Nlm_PointPtr pt)
  705.  
  706. {
  707. #ifdef WIN_MAC
  708.   Nlm_PointTool  ptool;
  709.  
  710.   if (pt != NULL) {
  711.     Nlm_PoinTToPointTool (*pt, &ptool);
  712.     GlobalToLocal (&ptool);
  713.     Nlm_PointToolToPoinT (ptool, pt);
  714.   }
  715. #endif
  716. #ifdef WIN_MSWIN
  717.   Nlm_PointTool  ptool;
  718.  
  719.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  720.     Nlm_PoinTToPointTool (*pt, &ptool);
  721.     ScreenToClient (Nlm_currentHWnd, &ptool);
  722.     Nlm_PointToolToPoinT (ptool, pt);
  723.   }
  724. #endif
  725. #ifdef WIN_X
  726. #endif
  727. }
  728.  
  729. #ifdef OS_MAC
  730. static void Nlm_CtoPstr (Nlm_CharPtr str)
  731.  
  732. {
  733. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  734.     c2pstr ((char *) str);
  735. #else
  736. #ifdef COMP_THINKC
  737.     CtoPstr ((char *) str);
  738. #endif
  739. #endif
  740. }
  741.  
  742. static void Nlm_PtoCstr (Nlm_CharPtr str)
  743.  
  744. {
  745. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  746.   p2cstr ((StringPtr) str);
  747. #else
  748. #ifdef COMP_THINKC
  749.   PtoCstr ((StringPtr) str);
  750. #endif
  751. #endif
  752. }
  753. #endif
  754.  
  755. extern void Nlm_CopyMode (void)
  756.  
  757. {
  758. #ifdef WIN_MAC
  759.   PenMode (patCopy);
  760. #ifdef DCLAP
  761.   TextMode (srcCopy);
  762. #else
  763.   TextMode (srcOr);
  764. #endif
  765. #endif
  766. #ifdef WIN_MSWIN
  767.   if (Nlm_currentHDC != NULL) {
  768.     SetROP2 (Nlm_currentHDC, R2_COPYPEN);
  769.   }
  770. #endif
  771. #ifdef WIN_X
  772.   currentFunction = GXcopy;
  773.   currentFillStyle = FillOpaqueStippled;
  774.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  775.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  776.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  777.   }
  778. #endif
  779.   currentMode = COPY_MODE;
  780. }
  781.  
  782. extern void Nlm_MergeMode (void)
  783.  
  784. {
  785. #ifdef WIN_MAC
  786.   PenMode (patOr);
  787.   TextMode (srcOr);
  788. #endif
  789. #ifdef WIN_MSWIN
  790.   if (Nlm_currentHDC != NULL) {
  791.     SetROP2 (Nlm_currentHDC, R2_MASKPEN);
  792.   }
  793. #endif
  794. #ifdef WIN_X
  795.   if (hasColor) {
  796.     currentFunction = GXand;
  797.   } else {
  798.     currentFunction = GXor;
  799.   }
  800.   currentFillStyle = FillStippled;
  801.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  802.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  803.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  804.   }
  805. #endif
  806.   currentMode = MERGE_MODE;
  807. }
  808.  
  809. extern void Nlm_InvertMode (void)
  810.  
  811. {
  812. #ifdef WIN_MAC
  813.   PenMode (patXor);
  814.   TextMode (srcXor);
  815. #endif
  816. #ifdef WIN_MSWIN
  817.   if (Nlm_currentHDC != NULL) {
  818.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  819.   }
  820. #endif
  821. #ifdef WIN_X
  822. #ifndef no_DCLAP
  823.   if (hasColor) {
  824.     currentFunction = GXequiv;
  825.   } else
  826. #endif 
  827.   {
  828.     currentFunction = GXinvert;
  829.   }
  830.   currentFillStyle = FillStippled;
  831.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  832.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  833.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  834.   }
  835. #endif
  836.   currentMode = INVERT_MODE;
  837. }
  838.  
  839. extern void Nlm_EraseMode (void)
  840.  
  841.  
  842. {
  843. #ifdef WIN_MAC
  844.   PenMode (patBic);
  845.   TextMode (srcBic);
  846. #endif
  847. #ifdef WIN_MSWIN
  848.   if (Nlm_currentHDC != NULL) {
  849.     SetROP2 (Nlm_currentHDC, R2_MERGENOTPEN);
  850.   }
  851. #endif
  852. #ifdef WIN_X
  853.   if (hasColor) {
  854.     currentFunction = GXorInverted;
  855.   } else {
  856.     currentFunction = GXand;
  857.   }
  858.   currentFillStyle = FillStippled;
  859.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  860.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  861.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  862.   }
  863. #endif
  864.   currentMode = ERASE_MODE;
  865. }
  866.  
  867. extern void Nlm_Black (void)
  868.  
  869. {
  870. #ifdef WIN_MAC
  871.   if (hasColorQD) {
  872.     Nlm_SelectColor (0, 0, 0);
  873.   } else {
  874.     Nlm_ChooseColor (blackColor);
  875.   }
  876. #endif
  877. #ifdef WIN_MSWIN
  878.   Nlm_ChooseColor (blackColor);
  879. #endif
  880. #ifdef WIN_X
  881.   Nlm_ChooseColor (blackColor);
  882. #endif
  883. }
  884.  
  885. extern void Nlm_Red (void)
  886.  
  887. {
  888. #ifdef WIN_MAC
  889.   if (hasColorQD) {
  890.     Nlm_SelectColor (255, 0, 0);
  891.   } else {
  892.     Nlm_ChooseColor (redColor);
  893.   }
  894. #endif
  895. #ifdef WIN_MSWIN
  896.   Nlm_ChooseColor (redColor);
  897. #endif
  898. #ifdef WIN_X
  899.   Nlm_ChooseColor (redColor);
  900. #endif
  901. }
  902.  
  903. extern void Nlm_Green (void)
  904.  
  905. {
  906. #ifdef WIN_MAC
  907.   if (hasColorQD) {
  908.     Nlm_SelectColor (0, 255, 0);
  909.   } else {
  910.     Nlm_ChooseColor (greenColor);
  911.   }
  912. #endif
  913. #ifdef WIN_MSWIN
  914.   Nlm_ChooseColor (greenColor);
  915. #endif
  916. #ifdef WIN_X
  917.   Nlm_ChooseColor (greenColor);
  918. #endif
  919. }
  920.  
  921. extern void Nlm_Blue (void)
  922.  
  923. {
  924. #ifdef WIN_MAC
  925.   if (hasColorQD) {
  926.     Nlm_SelectColor (0, 0, 255);
  927.   } else {
  928.     Nlm_ChooseColor (blueColor);
  929.   }
  930. #endif
  931. #ifdef WIN_MSWIN
  932.   Nlm_ChooseColor (blueColor);
  933. #endif
  934. #ifdef WIN_X
  935.   Nlm_ChooseColor (blueColor);
  936. #endif
  937. }
  938.  
  939. extern void Nlm_Cyan (void)
  940.  
  941. {
  942. #ifdef WIN_MAC
  943.   if (hasColorQD) {
  944.     Nlm_SelectColor (0, 255, 255);
  945.   } else {
  946.     Nlm_ChooseColor (cyanColor);
  947.   }
  948. #endif
  949. #ifdef WIN_MSWIN
  950.   Nlm_ChooseColor (cyanColor);
  951. #endif
  952. #ifdef WIN_X
  953.   Nlm_ChooseColor (cyanColor);
  954. #endif
  955. }
  956.  
  957. extern void Nlm_Magenta (void)
  958.  
  959. {
  960. #ifdef WIN_MAC
  961.   if (hasColorQD) {
  962.     Nlm_SelectColor (255, 0, 255);
  963.   } else {
  964.     Nlm_ChooseColor (magentaColor);
  965.   }
  966. #endif
  967. #ifdef WIN_MSWIN
  968.   Nlm_ChooseColor (magentaColor);
  969. #endif
  970. #ifdef WIN_X
  971.   Nlm_ChooseColor (magentaColor);
  972. #endif
  973. }
  974.  
  975. extern void Nlm_Yellow (void)
  976.  
  977. {
  978. #ifdef WIN_MAC
  979.   if (hasColorQD) {
  980.     Nlm_SelectColor (255, 255, 0);
  981.   } else {
  982.     Nlm_ChooseColor (yellowColor);
  983.   }
  984. #endif
  985. #ifdef WIN_MSWIN
  986.   Nlm_ChooseColor (yellowColor);
  987. #endif
  988. #ifdef WIN_X
  989.   Nlm_ChooseColor (yellowColor);
  990. #endif
  991. }
  992.  
  993. extern void Nlm_White (void)
  994.  
  995. {
  996. #ifdef WIN_MAC
  997.   if (hasColorQD) {
  998.     Nlm_SelectColor (255, 255, 255);
  999.   } else {
  1000.     Nlm_ChooseColor (whiteColor);
  1001.   }
  1002. #endif
  1003. #ifdef WIN_MSWIN
  1004.   Nlm_ChooseColor (whiteColor);
  1005. #endif
  1006. #ifdef WIN_X
  1007.   Nlm_ChooseColor (whiteColor);
  1008. #endif
  1009. }
  1010.  
  1011. extern void Nlm_Gray (void)
  1012.  
  1013. {
  1014.   Nlm_SelectColor (127, 127, 127);
  1015. }
  1016.  
  1017. extern void Nlm_LtGray (void)
  1018.  
  1019. {
  1020.   Nlm_SelectColor (191, 191, 191);
  1021. }
  1022.  
  1023. extern void Nlm_DkGray (void)
  1024.  
  1025. {
  1026.   Nlm_SelectColor (63, 63, 63);
  1027. }
  1028.  
  1029. extern void Nlm_SelectColor (Nlm_Uint1 red, Nlm_Uint1 green, Nlm_Uint1 blue)
  1030.  
  1031. {
  1032. #ifdef WIN_MAC
  1033.   RGBColor   color;
  1034.   Nlm_Uint2  bl;
  1035.   Nlm_Uint2  gn;
  1036.   Nlm_Uint2  rd;
  1037.  
  1038.   if (hasColorQD) {
  1039.     rd = (Nlm_Uint2) red;
  1040.     gn = (Nlm_Uint2) green;
  1041.     bl = (Nlm_Uint2) blue;
  1042.     color.red = rd << 8;
  1043.     color.green = gn << 8;
  1044.     color.blue = bl << 8;
  1045.     RGBForeColor (&color);
  1046.   } else if ((int) red + (int) green + (int) blue < 192) {
  1047.     Nlm_ChooseColor (blackColor);
  1048.   } else {
  1049.     Nlm_ChooseColor (whiteColor);
  1050.   }
  1051. #endif
  1052. #ifdef WIN_MSWIN
  1053.   COLORREF   color;
  1054.   Nlm_Uint2  bl;
  1055.   Nlm_Uint2  gn;
  1056.   Nlm_Uint2  rd;
  1057.  
  1058.   rd = (Nlm_Uint2) red;
  1059.   gn = (Nlm_Uint2) green;
  1060.   bl = (Nlm_Uint2) blue;
  1061.   color = RGB (rd, gn, bl);
  1062.   Nlm_ChooseColor (color);
  1063. #endif
  1064. #ifdef WIN_X
  1065.   Colormap   colormap;
  1066.   Nlm_Uint2  bl;
  1067.   Nlm_Uint2  gn;
  1068.   Nlm_Uint2  rd;
  1069.   XColor     xcolor;
  1070.  
  1071.   if (hasColor) {
  1072.     rd = (Nlm_Uint2) red;
  1073.     gn = (Nlm_Uint2) green;
  1074.     bl = (Nlm_Uint2) blue;
  1075.     xcolor.red = rd << 8;
  1076.     xcolor.green = gn << 8;
  1077.     xcolor.blue = bl << 8;
  1078.     if (Nlm_currentXDisplay != NULL) {
  1079.       colormap = DefaultColormap (Nlm_currentXDisplay, Nlm_currentXScreen);
  1080.       if (XAllocColor (Nlm_currentXDisplay, colormap, &xcolor) == 0) {
  1081.         xcolor.pixel = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  1082.       }
  1083.       Nlm_ChooseColor (xcolor.pixel);
  1084.     }
  1085.   } else if ((int) red + (int) green + (int) blue < 192) {
  1086.     Nlm_ChooseColor (blackColor);
  1087.   } else {
  1088.     Nlm_ChooseColor (whiteColor);
  1089.   }
  1090. #endif
  1091. }
  1092.  
  1093. extern Nlm_Uint4 Nlm_GetColor (void)
  1094.  
  1095. {
  1096. #ifdef WIN_MAC
  1097.   Nlm_Uint1  colors [4];
  1098.   RGBColor   foreColor;
  1099.   GrafPtr    port;
  1100.   Nlm_Int4   fgColor;
  1101.  
  1102.   fgColor = 0;
  1103.   if (hasColorQD) {
  1104.     GetForeColor (&foreColor);
  1105.     colors [0] = 0;
  1106.     colors [1] = (Nlm_Uint1) (foreColor.red >> 8);
  1107.     colors [2] = (Nlm_Uint1) (foreColor.green >> 8);
  1108.     colors [3] = (Nlm_Uint1) (foreColor.blue >> 8);
  1109.     fgColor = *((Nlm_Int4Ptr) colors);
  1110.   } else {
  1111.     GetPort (&port);
  1112.     if (port != NULL) {
  1113.       fgColor = port->fgColor;
  1114.     }
  1115.   }
  1116.   return (Nlm_Uint4) fgColor;
  1117. #endif
  1118. #ifdef WIN_MSWIN
  1119.   Nlm_Int4  fgColor;
  1120.  
  1121.   fgColor = 0;
  1122.   if (Nlm_currentHDC != NULL) {
  1123.     fgColor = GetTextColor (Nlm_currentHDC);
  1124.   }
  1125.   return (Nlm_Uint4) fgColor;
  1126. #endif
  1127. #ifdef WIN_X
  1128.   Nlm_Uint4  fgColor;
  1129.  
  1130.   fgColor = currentFgColor;
  1131.   return (Nlm_Uint4) fgColor;
  1132. #endif
  1133. }
  1134.  
  1135. extern void Nlm_SetColor (Nlm_Uint4 color)
  1136.  
  1137. {
  1138. #ifdef WIN_MAC
  1139.   Nlm_Uint2  bl;
  1140.   Nlm_Uint2  gn;
  1141.   Nlm_Uint2  rd;
  1142.   Nlm_Uint1  colors [4];
  1143.   RGBColor   foreColor;
  1144.   GrafPtr    port;
  1145.  
  1146.   if (hasColorQD) {
  1147.     *((Nlm_Int4Ptr) colors) = color;
  1148.     rd = (Nlm_Uint2) colors [1];
  1149.     gn = (Nlm_Uint2) colors [2];
  1150.     bl = (Nlm_Uint2) colors [3];
  1151.     foreColor.red = rd << 8;
  1152.     foreColor.green = gn << 8;
  1153.     foreColor.blue = bl << 8;
  1154.     RGBForeColor (&foreColor);
  1155.   } else {
  1156.     GetPort (&port);
  1157.     if (port != NULL) {
  1158.       ForeColor ((Nlm_Int4) color);
  1159.     }
  1160.   }
  1161. #endif
  1162. #ifdef WIN_MSWIN
  1163.   if (Nlm_currentHDC != NULL) {
  1164.     SetTextColor (Nlm_currentHDC, (Nlm_Int4) color);
  1165.     Nlm_RecreateBrushes ();
  1166.   }
  1167. #endif
  1168. #ifdef WIN_X
  1169.   XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, color);
  1170.   currentFgColor = color;
  1171. #endif
  1172. }
  1173.  
  1174. extern void Nlm_InvertColors (void)
  1175.  
  1176. {
  1177. #ifdef WIN_MAC
  1178.   RGBColor  backColor;
  1179.   RGBColor  foreColor;
  1180.   GrafPtr   port;
  1181.   Nlm_Int4  bkColor;
  1182.   Nlm_Int4  fgColor;
  1183.  
  1184.   if (hasColorQD) {
  1185.     GetForeColor (&foreColor);
  1186.     GetBackColor (&backColor);
  1187.     RGBForeColor (&backColor);
  1188.     RGBBackColor (&foreColor);
  1189.   } else {
  1190.     GetPort (&port);
  1191.     if (port != NULL) {
  1192.       fgColor = port->fgColor;
  1193.       bkColor = port->bkColor;
  1194.       ForeColor (bkColor);
  1195.       BackColor (fgColor);
  1196.     }
  1197.   }
  1198. #endif
  1199. #ifdef WIN_MSWIN
  1200.   Nlm_Int4  bkColor;
  1201.   Nlm_Int4  fgColor;
  1202.  
  1203.   if (Nlm_currentHDC != NULL) {
  1204.     fgColor = GetTextColor (Nlm_currentHDC);
  1205.     bkColor = GetBkColor (Nlm_currentHDC);
  1206.     SetTextColor (Nlm_currentHDC, bkColor);
  1207.     SetBkColor (Nlm_currentHDC, fgColor);
  1208.     Nlm_RecreateBrushes ();
  1209.   }
  1210. #endif
  1211. #ifdef WIN_X
  1212.   Nlm_Uint4  newBkColor;
  1213.   Nlm_Uint4  newFgColor;
  1214.  
  1215.   newBkColor = currentFgColor;
  1216.   newFgColor = currentBkColor;
  1217.   XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, newBkColor);
  1218.   XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, newFgColor);
  1219.   currentBkColor = newBkColor;
  1220.   currentFgColor = newFgColor;
  1221. #endif
  1222. }
  1223.  
  1224.  
  1225. #ifdef DCLAP
  1226. extern void Nlm_PenPattern(void *pat)
  1227. {
  1228. #ifdef WIN_MAC
  1229.   PenPat ((ConstPatternParam) pat); 
  1230. #endif
  1231. #ifdef WIN_MSWIN
  1232.   Nlm_SelectPattern (PS_SOLID, 1, pat);
  1233. #endif
  1234. #ifdef WIN_X
  1235.   Nlm_SelectPattern (pat);
  1236. #endif
  1237. }
  1238. #endif
  1239.  
  1240.  
  1241. extern void Nlm_Solid (void)
  1242.  
  1243. {
  1244. #ifdef WIN_MAC
  1245.   PenPat ((ConstPatternParam) blackPat); 
  1246. #endif
  1247. #ifdef WIN_MSWIN
  1248.   Nlm_SelectPattern (PS_SOLID, 1, blackPat);
  1249. #endif
  1250. #ifdef WIN_X
  1251.   XGCValues  values;
  1252.  
  1253.   Nlm_SelectPattern (blackPat);
  1254.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1255.     values.line_style = LineSolid;
  1256.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineStyle, &values);
  1257.   }
  1258. #endif
  1259. }
  1260.  
  1261. extern void Nlm_Dark (void)
  1262.  
  1263. {
  1264. #ifdef WIN_MAC
  1265.   PenPat ((ConstPatternParam) dkGrayPat);
  1266. #endif
  1267. #ifdef WIN_MSWIN
  1268.   Nlm_SelectPattern (PS_SOLID, 1, dkGrayPat);
  1269. #endif
  1270. #ifdef WIN_X
  1271.   Nlm_SelectPattern (dkGrayPat);
  1272. #endif
  1273. }
  1274.  
  1275. extern void Nlm_Medium (void)
  1276.  
  1277. {
  1278. #ifdef WIN_MAC
  1279.   PenPat ((ConstPatternParam) grayPat);
  1280. #endif
  1281. #ifdef WIN_MSWIN
  1282.   Nlm_SelectPattern (PS_SOLID, 1, grayPat);
  1283. #endif
  1284. #ifdef WIN_X
  1285.   Nlm_SelectPattern (grayPat);
  1286. #endif
  1287. }
  1288.  
  1289. extern void Nlm_Light (void)
  1290.  
  1291. {
  1292. #ifdef WIN_MAC
  1293.   PenPat ((ConstPatternParam) ltGrayPat);
  1294. #endif
  1295. #ifdef WIN_MSWIN
  1296.   Nlm_SelectPattern (PS_SOLID, 1, ltGrayPat);
  1297. #endif
  1298. #ifdef WIN_X
  1299.   Nlm_SelectPattern (ltGrayPat);
  1300. #endif
  1301. }
  1302.  
  1303. extern void Nlm_Empty (void)
  1304.  
  1305.  
  1306. {
  1307. #ifdef WIN_MAC
  1308.   PenPat ((ConstPatternParam) whitePat);
  1309. #endif
  1310. #ifdef WIN_MSWIN
  1311.   Nlm_SelectPattern (PS_SOLID, 1, whitePat);
  1312. #endif
  1313. #ifdef WIN_X
  1314.   Nlm_SelectPattern (whitePat);
  1315. #endif
  1316. }
  1317.  
  1318. extern void Nlm_Dotted (void)
  1319.  
  1320. {
  1321. #ifdef WIN_MAC
  1322.   PenPat ((ConstPatternParam) dotPat);
  1323. #endif
  1324. #ifdef WIN_MSWIN
  1325.   Nlm_SelectPattern (PS_DOT, 1, dotPat);
  1326. #endif
  1327. #ifdef WIN_X
  1328.   XGCValues  values;
  1329.  
  1330.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1331.     values.line_style = LineOnOffDash;
  1332.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineStyle, &values);
  1333.   }
  1334. #endif
  1335. }
  1336.  
  1337. extern void Nlm_Dashed (void)
  1338.  
  1339. {
  1340. #ifdef WIN_MAC
  1341.   PenPat ((ConstPatternParam) dashPat);
  1342. #endif
  1343. #ifdef WIN_MSWIN
  1344.   Nlm_SelectPattern (PS_DASH, 1, dashPat);
  1345. #endif
  1346. #ifdef WIN_X
  1347.   XGCValues  values;
  1348.  
  1349.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1350.     values.line_style = LineOnOffDash;
  1351.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineStyle, &values);
  1352.   }
  1353. #endif
  1354. }
  1355.  
  1356. extern void Nlm_WidePen (Nlm_Int2 width)
  1357.  
  1358.  
  1359. {
  1360. #ifdef WIN_MAC
  1361.   PenPat ((ConstPatternParam) blackPat);
  1362.   PenSize (width, width);
  1363. #endif
  1364. #ifdef WIN_MSWIN
  1365.   Nlm_SelectPattern (PS_SOLID, width, blackPat);
  1366. #endif
  1367. #ifdef WIN_X
  1368.   XGCValues  values;
  1369.  
  1370.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1371.     values.line_width = width;
  1372.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineWidth, &values);
  1373.   }
  1374. #endif
  1375. }
  1376.  
  1377. static Nlm_FonT Nlm_CreateNewFont (Nlm_CharPtr name, Nlm_Int2 size,
  1378.                                    Nlm_Boolean bld, Nlm_Boolean itlc,
  1379.                                    Nlm_Boolean undrln, Nlm_CharPtr fmly)
  1380.  
  1381. {
  1382.   Nlm_Byte      charSet;
  1383.   Nlm_FontTool  hdl;
  1384.   Nlm_Int2      num;
  1385.   Nlm_FonT      rsult;
  1386.   Nlm_Int2      scale;
  1387.   Nlm_Int2      styl;
  1388.   Nlm_Int2      weight;
  1389. #ifdef WIN_MAC
  1390.   Nlm_Char      temp [256];
  1391. #endif
  1392. #ifdef WIN_MSWIN
  1393.   BYTE          family;
  1394.   HDC           hDC;
  1395.   POINT         ptool;
  1396. #endif
  1397. #ifdef WIN_X
  1398.   Nlm_Char      ptsize [16];
  1399.   Nlm_Char      temp [256];
  1400. #endif
  1401.  
  1402.   rsult = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  1403.   if (rsult != NULL) {
  1404.     scale = size;
  1405. #ifdef WIN_MAC
  1406.     hdl = NULL;
  1407.     num = 0;
  1408.     if (name != NULL) {
  1409.       Nlm_StringNCpy (temp, name, sizeof (temp));
  1410.       Nlm_CtoPstr (temp);
  1411.       GetFNum ((StringPtr) temp, &num);
  1412. #ifndef DCLAP
  1413.       if (num == 0 && fmly != NULL && fmly [0] != '\0') {
  1414.         if (Nlm_StringICmp (fmly, "Roman") == 0) {
  1415.           num = 0; /* chicago */
  1416.         } else if (Nlm_StringICmp (fmly, "Swiss") == 0) {
  1417.           num = 3; /* geneva */
  1418.         } else if (Nlm_StringICmp (fmly, "Modern") == 0) {
  1419.           num = 4; /* monaco */
  1420.         } else if (Nlm_StringICmp (fmly, "Script") == 0) {
  1421.           num = 0; /* chicago  */
  1422.         } else if (Nlm_StringICmp (fmly, "Decorative") == 0) {
  1423.           num = 0; /* chicago  */
  1424.         }
  1425.       }
  1426. #endif
  1427.     }
  1428. #ifdef DCLAP
  1429.     if (num == 0 && fmly != NULL && fmly [0] != '\0') {
  1430.       if (Nlm_StringICmp (fmly, "Roman") == 0)  
  1431.           num = 20; /* times roman */
  1432.       else if (Nlm_StringICmp (fmly, "Swiss") == 0) 
  1433.           num = 21; /* helvetica */
  1434.       else if (Nlm_StringICmp (fmly, "Modern") == 0) 
  1435.           num = 22;  /* courier */
  1436.       else if (Nlm_StringICmp (fmly, "Script") == 0) 
  1437.           num = 20;     /* 18 == Zapf Chancery, !? or times */
  1438.       else if (Nlm_StringICmp (fmly, "Decorative") == 0) 
  1439.           num = 20; /* times roman */
  1440.       else
  1441.                num = 3; /* geneva == builtin == appl font */           
  1442.       }
  1443. #endif
  1444.    
  1445.     styl = 0;
  1446.     if (bld) {
  1447.       styl += bold;
  1448.     }
  1449.     if (itlc) {
  1450.       styl += italic;
  1451.     }
  1452.     if (undrln) {
  1453.       styl += underline;
  1454.     }
  1455. #endif
  1456. #ifdef WIN_MSWIN
  1457.     hdl = NULL;
  1458.     num = 0;
  1459.     styl = 0;
  1460.     if (bld) {
  1461.       weight = FW_BOLD;
  1462.     } else {
  1463.       weight = FW_NORMAL;
  1464.     }
  1465.     if (Nlm_StringICmp (name, "Symbol") == 0) {
  1466.       charSet = SYMBOL_CHARSET;
  1467.     } else if (Nlm_StringICmp (name, "Terminal") == 0) {
  1468.       charSet = OEM_CHARSET;
  1469.     } else {
  1470.       charSet = ANSI_CHARSET;
  1471.     }
  1472.     family = FF_DONTCARE;
  1473.     if (fmly != NULL && fmly [0] != '\0') {
  1474.       if (Nlm_StringICmp (fmly, "Roman") == 0) {
  1475.         family = FF_ROMAN;
  1476.       } else if (Nlm_StringICmp (fmly, "Swiss") == 0) {
  1477.         family = FF_SWISS;
  1478.       } else if (Nlm_StringICmp (fmly, "Modern") == 0) {
  1479.         family = FF_MODERN;
  1480.       } else if (Nlm_StringICmp (fmly, "Script") == 0) {
  1481.         family = FF_SCRIPT;
  1482.       } else if (Nlm_StringICmp (fmly, "Decorative") == 0) {
  1483.         family = FF_DECORATIVE;
  1484.       }
  1485.     }
  1486.     hDC = CreateCompatibleDC (NULL);
  1487.     SetMapMode (hDC, MM_ANISOTROPIC);
  1488.     SetWindowExtEx (hDC, 1440, 1440, NULL);
  1489.     SetViewportExtEx (hDC, GetDeviceCaps (hDC, LOGPIXELSX),
  1490.                       GetDeviceCaps (hDC, LOGPIXELSY), NULL);
  1491. #ifdef DCLAP
  1492.         DeleteDC (hDC);
  1493.         hdl = CreateFont (-size, 0, 0, 0, weight, itlc, undrln, FALSE,
  1494.                                             charSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1495.                                             DEFAULT_QUALITY, (BYTE) (DEFAULT_PITCH | family), name);
  1496. #else
  1497.         ptool.x = 0;
  1498.     ptool.y = 20 * size;
  1499.     LPtoDP (hDC, &ptool, 1);
  1500.     DeleteDC (hDC);
  1501.     scale = (Nlm_Int2) ptool.y;
  1502.     hdl = CreateFont (scale, 0, 0, 0, weight, itlc, undrln, FALSE,
  1503.                       charSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1504.                       DEFAULT_QUALITY, (BYTE) (DEFAULT_PITCH | family), name);
  1505.     /*
  1506.     hdl = CreateFont (-size, 0, 0, 0, weight, itlc, undrln, FALSE,
  1507.                       charSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1508.                       DEFAULT_QUALITY, (BYTE) (DEFAULT_PITCH | family), name);
  1509.     */
  1510. #endif
  1511.  
  1512. #endif
  1513. #ifdef WIN_X
  1514.     num = 0;
  1515.     styl = 0;
  1516.     hdl = NULL;
  1517.     if (name != NULL && Nlm_currentXDisplay != NULL) {
  1518.       StringCpy (temp, "-*-");
  1519.       StringCat (temp, name);
  1520.       StringCat (temp, "-");
  1521.             /* dgg ! some use "demi" and "light" ! */
  1522.       if (bld) {
  1523.         StringCat (temp, "bold-");
  1524.       } else {
  1525.         StringCat (temp, "medium-");
  1526.       }
  1527.             /* dgg ! some use "o", some use "i" for italic !! */
  1528.       if (itlc) {
  1529.         StringCat (temp, "o-");
  1530.       } else {
  1531.         StringCat (temp, "r-");
  1532.       }
  1533.       StringCat (temp, "*--");
  1534.       sprintf (ptsize, "%d", (int) size);
  1535.       StringCat (temp, ptsize);
  1536.       StringCat (temp, "-*");
  1537.       hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1538.       if (hdl == NULL) {
  1539.  
  1540. #ifdef DCLAP
  1541.                 int    size2, ipoints, ipixels;
  1542.                 char *sbold, *sitalic;
  1543.  
  1544.                 /* try scalable font ! */
  1545.                 if (itlc) sitalic= "i"; else sitalic= "r";   /* or "o" and "r" */
  1546.                 if (bld) sbold= "bold"; else sbold= "medium"; /* or "demi" and "light" */
  1547.                 ipoints= 0;    /* to select scalable font */
  1548.                 ipixels= size * 10; /* ?? */
  1549.               sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1550.         hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1551.         if (hdl) goto fontokay;
  1552.                 if (itlc) {
  1553.                      sitalic= "o";
  1554.                    sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1555.            hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1556.            if (hdl) goto fontokay;
  1557.                      }
  1558.                 if (bld) {
  1559.                      sbold= "demi";
  1560.                    sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1561.            hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1562.            if (hdl) goto fontokay;
  1563.                      }
  1564.  
  1565.                 /* try it based on family... */
  1566.                 if (fmly != NULL && fmly [0] != '\0') {
  1567.                     ipoints= 0;    /* to select scalable font */
  1568.                     ipixels= size * 10; /* ?? */
  1569.                     if (itlc) sitalic= "i"; else sitalic= "r";   /* or "o" and "r" */
  1570.                     if (bld) sbold= "bold"; else sbold= "medium"; /* or "demi" and "light" */
  1571.               if (Nlm_StringICmp (fmly, "Roman") == 0
  1572.                   && Nlm_StringICmp(name, "times") != 0)  
  1573.                   name= "times"; 
  1574.               else if (Nlm_StringICmp (fmly, "Swiss") == 0
  1575.                   && Nlm_StringICmp(name, "helvetica") != 0)  
  1576.                   name= "helvetica"; 
  1577.               else if (Nlm_StringICmp (fmly, "Modern") == 0
  1578.                   && Nlm_StringICmp(name, "courier") != 0)  
  1579.                   name= "courier"; 
  1580.               else if (Nlm_StringICmp (fmly, "Script") == 0
  1581.                   && Nlm_StringICmp(name, "times") != 0)  
  1582.                   name= "times"; 
  1583.               else if (Nlm_StringICmp (fmly, "Decorative") == 0
  1584.                   && Nlm_StringICmp(name, "times") != 0)  
  1585.                   name= "times"; 
  1586.               else if (Nlm_StringICmp(name, "helvetica") != 0)  
  1587.                   name= "helvetica"; 
  1588.                   sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1589.             hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1590.             if (hdl) goto fontokay;
  1591.                 }
  1592.  
  1593.         /* try font sizes w/o other extra -- looks good */
  1594.         size2= 10 + size;
  1595.         size--; /* start 1 lower */
  1596.         do {
  1597.             sprintf(temp,"-*-%s-*--%d-*",name, (int)size);
  1598.           hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1599.           if (hdl) goto fontokay;
  1600.           size ++;
  1601.         } while (size < size2);
  1602.  
  1603. #endif
  1604.  
  1605.         StringCpy (temp, "-*-");
  1606.         StringCat (temp, name);
  1607.         StringCat (temp, "-*");
  1608.         hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1609.         if (hdl == NULL) {
  1610.           StringCpy (temp, "-*-helvetica-bold-r-*--14-*");
  1611.           hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, TRUE);
  1612.         }
  1613.       }
  1614.     }
  1615. #ifdef DCLAP
  1616. fontokay:
  1617. #endif
  1618.  
  1619. #endif
  1620.     Nlm_LoadFontData (rsult, NULL, name, size, scale, bld,
  1621.                       itlc, undrln, num, styl, hdl, NULL);
  1622.   }
  1623.   return rsult;
  1624. }
  1625.  
  1626. static Nlm_FonT Nlm_FindFont (Nlm_CharPtr name, Nlm_Int2 size,
  1627.                               Nlm_Boolean bld, Nlm_Boolean itlc,
  1628.                               Nlm_Boolean undrln)
  1629.  
  1630. {
  1631.   Nlm_FontData  fdata;
  1632.   Nlm_FonT      p;
  1633.   Nlm_FonT      rsult;
  1634.  
  1635.   rsult = NULL;
  1636.   if (name != NULL && name [0] != '\0') {
  1637.     p = Nlm_fontList;
  1638.     while (p != NULL && rsult == NULL) {
  1639.       Nlm_GetFontData (p, &fdata);
  1640.       if ((Nlm_StringICmp (fdata.name, name) == 0) &&
  1641.          fdata.size == size && fdata.bld == bld &&
  1642.          fdata.ital == itlc && fdata.undlin == undrln) {
  1643.         rsult = p;
  1644.       }
  1645.       p = fdata.next;
  1646.     }
  1647.   }
  1648.   return rsult;
  1649. }
  1650.  
  1651. extern Nlm_FonT Nlm_GetFont (Nlm_CharPtr name, Nlm_Int2 size,
  1652.                              Nlm_Boolean bld, Nlm_Boolean itlc,
  1653.                              Nlm_Boolean undrln, Nlm_CharPtr family)
  1654.  
  1655. {
  1656.   Nlm_FontData  fdata;
  1657.   Nlm_FonT      rsult;
  1658.  
  1659.   rsult = NULL;
  1660.   if (name != NULL && name [0] != '\0') {
  1661. #ifdef DCLAP
  1662. #ifdef WIN_MSWIN
  1663.         /* need to do here -- MSWIN chokes if we try to CreateNewFont lots of times */
  1664.             if (Nlm_StringICmp (name, "Courier") == 0) {
  1665.                 name= "Courier New";      /* newCourier= TRUE; */            
  1666.                 }
  1667. #endif
  1668. #endif
  1669.     rsult = Nlm_FindFont (name, size, bld, itlc, undrln);
  1670.     if (rsult == NULL) {
  1671.       rsult = Nlm_CreateNewFont (name, size, bld, itlc, undrln, family);
  1672.       Nlm_GetFontData (rsult, &fdata);
  1673.       fdata.next = Nlm_fontList;
  1674.       Nlm_SetFontData (rsult, &fdata);
  1675.       Nlm_fontList = rsult;
  1676.     }
  1677.   }
  1678.   return rsult;
  1679. }
  1680.  
  1681. static Nlm_FonT Nlm_ParseFontSpec (Nlm_CharPtr spec)
  1682.  
  1683. {
  1684.   Nlm_Boolean  bold;
  1685.   Nlm_CharPtr  fmly;
  1686.   Nlm_Boolean  ital;
  1687.   Nlm_Char     name [128];
  1688.   Nlm_CharPtr  p;
  1689.   Nlm_CharPtr  q;
  1690.   Nlm_CharPtr  r;
  1691.   Nlm_FonT     rsult;
  1692.   Nlm_Int2     size;
  1693.   Nlm_Char     temp [128];
  1694.   Nlm_Boolean  undr;
  1695.   int          val;
  1696.  
  1697.   rsult = NULL;
  1698.   if (spec != NULL && spec [0] != '\0') {
  1699.     fmly = NULL;
  1700.     bold = FALSE;
  1701.     ital = FALSE;
  1702.     undr = FALSE;
  1703.     Nlm_StringNCpy (name, spec, sizeof (name) - 1);
  1704.     p = Nlm_StringChr (name, ',');
  1705.     if (p != NULL) {
  1706.       *p = '\0';
  1707.       p++;
  1708.       q = Nlm_StringChr (p, ',');
  1709.       if (q != NULL) {
  1710.         *q = '\0';
  1711.         q++;
  1712.       }
  1713.       r = Nlm_StringChr (q, 'B');
  1714.       if (r == NULL) {
  1715.         r = Nlm_StringChr (q, 'b');
  1716.       }
  1717.       if (r != NULL) {
  1718.         bold = TRUE;
  1719.       }
  1720.       r = Nlm_StringChr (q, 'I');
  1721.       if (r == NULL) {
  1722.         r = Nlm_StringChr (q, 'i');
  1723.       }
  1724.       if (r != NULL) {
  1725.         ital = TRUE;
  1726.       }
  1727.       r = Nlm_StringChr (q, 'U');
  1728.       if (r == NULL) {
  1729.         r = Nlm_StringChr (q, 'u');
  1730.       }
  1731.       if (r != NULL) {
  1732.         undr = TRUE;
  1733.       }
  1734.       Nlm_StringNCpy (temp, p, sizeof (temp) - 1);
  1735.       if (sscanf (temp, "%d", &val) != EOF) {
  1736.         size = (Nlm_Int2) val;
  1737.         rsult = Nlm_GetFont (name, size, bold, ital, undr, fmly);
  1738.       }
  1739.     }
  1740.   }
  1741.   return rsult;
  1742. }
  1743.  
  1744. extern Nlm_FonT Nlm_ParseFont (Nlm_CharPtr spec)
  1745.  
  1746. {
  1747.   Nlm_Char     name [128];
  1748.   Nlm_CharPtr  p;
  1749.   Nlm_FonT     prtr;
  1750.   Nlm_CharPtr  q;
  1751.   Nlm_FonT     rsult;
  1752.  
  1753.   rsult = NULL;
  1754.   if (spec != NULL && spec [0] != '\0') {
  1755.     Nlm_StringNCpy (name, spec, sizeof (name) - 1);
  1756.     p = Nlm_StringChr (name, '|');
  1757.     if (p != NULL) {
  1758.       *p = '\0';
  1759.       p++;
  1760.       while (*p == ' ') {
  1761.         p++;
  1762.       }
  1763.       q = name;
  1764.       while (*q == ' ') {
  1765.         q++;
  1766.       }
  1767.       rsult = Nlm_ParseFontSpec (q);
  1768.       prtr = Nlm_ParseFontSpec (p);
  1769.       Nlm_AssignPrinterFont (rsult, prtr);
  1770.     } else {
  1771.       q = name;
  1772.       while (*q == ' ') {
  1773.         q++;
  1774.       }
  1775.       rsult = Nlm_ParseFontSpec (q);
  1776.     }
  1777.   }
  1778.   return rsult;
  1779. }
  1780.  
  1781. extern void Nlm_SelectFont (Nlm_FonT f)
  1782.  
  1783. {
  1784.   Nlm_FontData  fdata;
  1785.  
  1786.   if (f != NULL) {
  1787.     Nlm_GetFontData (f, &fdata);
  1788.     if (fdata.print != NULL && Nlm_nowPrinting) {
  1789.       f = fdata.print;
  1790.       Nlm_GetFontData (f, &fdata);
  1791.     }
  1792. #ifdef WIN_MAC
  1793.     TextFont (fdata.number);
  1794.     TextSize (fdata.size);
  1795.     TextFace (fdata.style);
  1796. #endif
  1797. #ifdef WIN_MSWIN
  1798.     if (Nlm_currentHDC != NULL) {
  1799.       SelectObject (Nlm_currentHDC, fdata.handle);
  1800.     }
  1801. #endif
  1802. #ifdef WIN_X
  1803.     if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1804.       if (fdata.handle != NULL) {
  1805.         XSetFont (Nlm_currentXDisplay, Nlm_currentXGC, fdata.handle->fid);
  1806.         currentFont = fdata.handle;
  1807.       }
  1808.     }
  1809. #endif
  1810.     Nlm_fontInUse = f;
  1811.   }
  1812. }
  1813.  
  1814. extern void Nlm_AssignPrinterFont (Nlm_FonT scrnFont, Nlm_FonT prtrFont)
  1815.  
  1816. {
  1817.   Nlm_FontData  fdata;
  1818.  
  1819.   if (scrnFont != NULL) {
  1820.     Nlm_GetFontData (scrnFont, &fdata);
  1821.     fdata.print = prtrFont;
  1822.     Nlm_SetFontData (scrnFont, &fdata);
  1823.   }
  1824. }
  1825.  
  1826. extern Nlm_Int2 Nlm_CharWidth (Nlm_Char ch)
  1827.  
  1828. {
  1829. #ifdef WIN_MAC
  1830.   return (CharWidth (ch));
  1831. #endif
  1832. #ifdef WIN_MSWIN
  1833.   Nlm_Char  str [4];
  1834.  
  1835.   str [0] = ch;
  1836.   str [1] = '\0';
  1837.   return (Nlm_TextWidth (str, 1));
  1838. #endif
  1839. #ifdef WIN_X
  1840.   Nlm_Char  str [4];
  1841.  
  1842.   str [0] = ch;
  1843.   str [1] = '\0';
  1844.   return (Nlm_TextWidth (str, 1));
  1845. #endif
  1846. }
  1847.  
  1848. extern Nlm_Int2 Nlm_StringWidth (Nlm_CharPtr text)
  1849.  
  1850. {
  1851.   return Nlm_TextWidth (text, Nlm_StringLen (text));
  1852. }
  1853.  
  1854. extern Nlm_Int2 Nlm_TextWidth (Nlm_CharPtr text, Nlm_sizeT len)
  1855.  
  1856. {
  1857. #ifdef WIN_MAC
  1858.   Nlm_Int2  rsult;
  1859.  
  1860.   rsult = 0;
  1861.   if (text != NULL && len > 0) {
  1862.     rsult = TextWidth (text, 0, (Nlm_Int2) len);
  1863.   }
  1864.   return rsult;
  1865. #endif
  1866. #ifdef WIN_MSWIN
  1867.   Nlm_Int2  rsult;
  1868.   HDC       hDC;
  1869.   SIZE      tag;
  1870.  
  1871.   rsult = 0;
  1872.   if (text != NULL && len > 0) {
  1873.     if (Nlm_currentHDC != NULL) {
  1874.       GetTextExtentPoint (Nlm_currentHDC, text, (Nlm_Int2) len, &tag);
  1875.     } else {
  1876.       hDC = CreateIC ("DISPLAY", NULL, NULL, NULL);
  1877.       GetTextExtentPoint (hDC, text, (Nlm_Int2) len, &tag);
  1878.       DeleteDC (hDC);
  1879.     }
  1880.     rsult = (Nlm_Int2) tag.cx;
  1881.   }
  1882.   return rsult;
  1883. #endif
  1884. #ifdef WIN_X
  1885.   Nlm_Int2  rsult;
  1886.  
  1887.   rsult = 0;
  1888.   if (text != NULL && len > 0 && Nlm_GetTextMetrics ()) {
  1889.     rsult = XTextWidth (&fontInfo, text, (int) len);
  1890.   }
  1891.   return rsult;
  1892. #endif
  1893. }
  1894.  
  1895. extern Nlm_Int2 Nlm_Ascent (void)
  1896.  
  1897. {
  1898. #ifdef WIN_MAC
  1899.   FontInfo  fontinfo;
  1900.  
  1901.   GetFontInfo (&fontinfo);
  1902.   return (fontinfo.ascent);
  1903. #endif
  1904. #ifdef WIN_MSWIN
  1905.   Nlm_Int2  rsult;
  1906.  
  1907.   rsult = 0;
  1908.   if (Nlm_GetTextMetrics ()) {
  1909.     rsult = (Nlm_Int2) textMetrics.tmAscent;
  1910.   }
  1911.   return rsult;
  1912. #endif
  1913. #ifdef WIN_X
  1914.   Nlm_Int2  rsult;
  1915.  
  1916.   rsult = 0;
  1917.   if (Nlm_GetTextMetrics ()) {
  1918.     rsult = fontInfo.ascent;
  1919.   }
  1920.   return rsult;
  1921. #endif
  1922. }
  1923.  
  1924. extern Nlm_Int2 Nlm_Descent (void)
  1925.  
  1926. {
  1927. #ifdef WIN_MAC
  1928.   FontInfo  fontinfo;
  1929.  
  1930.   GetFontInfo (&fontinfo);
  1931.   return (fontinfo.descent);
  1932. #endif
  1933. #ifdef WIN_MSWIN
  1934.   Nlm_Int2  rsult;
  1935.  
  1936.   rsult = 0;
  1937.   if (Nlm_GetTextMetrics ()) {
  1938.     rsult = (Nlm_Int2) textMetrics.tmDescent;
  1939.   }
  1940.   return rsult;
  1941. #endif
  1942. #ifdef WIN_X
  1943.   Nlm_Int2  rsult;
  1944.  
  1945.   rsult = 0;
  1946.   if (Nlm_GetTextMetrics ()) {
  1947.     rsult = fontInfo.descent;
  1948.   }
  1949.   return rsult;
  1950. #endif
  1951. }
  1952.  
  1953. extern Nlm_Int2 Nlm_Leading (void)
  1954.  
  1955. {
  1956. #ifdef WIN_MAC
  1957.   FontInfo  fontinfo;
  1958.  
  1959.   GetFontInfo (&fontinfo);
  1960.   return (fontinfo.leading);
  1961. #endif
  1962. #ifdef WIN_MSWIN
  1963.   Nlm_Int2  rsult;
  1964.  
  1965.   rsult = 0;
  1966.   if (Nlm_GetTextMetrics ()) {
  1967.     rsult = (Nlm_Int2) textMetrics.tmExternalLeading;
  1968.   }
  1969.   return rsult;
  1970. #endif
  1971. #ifdef WIN_X
  1972.   return 0;
  1973. #endif
  1974. }
  1975.  
  1976. extern Nlm_Int2 Nlm_FontHeight (void)
  1977.  
  1978. {
  1979. #ifdef WIN_MAC
  1980.   FontInfo  fontinfo;
  1981.  
  1982.   GetFontInfo (&fontinfo);
  1983.   return (fontinfo.ascent + fontinfo.descent);
  1984. #endif
  1985. #ifdef WIN_MSWIN
  1986.   Nlm_Int2  rsult;
  1987.  
  1988.   rsult = 0;
  1989.   if (Nlm_GetTextMetrics ()) {
  1990.     rsult = (Nlm_Int2) textMetrics.tmHeight;
  1991.   }
  1992.   return rsult;
  1993. #endif
  1994. #ifdef WIN_X
  1995.   Nlm_Int2  rsult;
  1996.  
  1997.   rsult = 0;
  1998.   if (Nlm_GetTextMetrics ()) {
  1999.     rsult = (fontInfo.ascent + fontInfo.descent);
  2000.   }
  2001.   return rsult;
  2002. #endif
  2003. }
  2004.  
  2005. extern Nlm_Int2 Nlm_LineHeight (void)
  2006.  
  2007. {
  2008. #ifdef WIN_MAC
  2009.   FontInfo  fontinfo;
  2010.  
  2011.   GetFontInfo (&fontinfo);
  2012.   return (fontinfo.ascent + fontinfo.descent + fontinfo.leading);
  2013. #endif
  2014. #ifdef WIN_MSWIN
  2015.   Nlm_Int2  rsult;
  2016.  
  2017.   rsult = 0;
  2018.   if (Nlm_GetTextMetrics ()) {
  2019.     rsult = (Nlm_Int2) (textMetrics.tmHeight + textMetrics.tmExternalLeading);
  2020.   }
  2021.   return rsult;
  2022. #endif
  2023. #ifdef WIN_X
  2024.   Nlm_Int2  rsult;
  2025.  
  2026.   rsult = 0;
  2027.   if (Nlm_GetTextMetrics ()) {
  2028.     rsult = (fontInfo.ascent + fontInfo.descent);
  2029.   }
  2030.   return rsult;
  2031. #endif
  2032. }
  2033.  
  2034. extern Nlm_Int2 Nlm_MaxCharWidth (void)
  2035.  
  2036. {
  2037. #ifdef WIN_MAC
  2038.   FontInfo  fontinfo;
  2039.  
  2040.   GetFontInfo (&fontinfo);
  2041.   return (fontinfo.widMax);
  2042. #endif
  2043. #ifdef WIN_MSWIN
  2044.   Nlm_Int2  rsult;
  2045.  
  2046.   rsult = 0;
  2047.   if (Nlm_GetTextMetrics ()) {
  2048.     rsult = (Nlm_Int2) textMetrics.tmMaxCharWidth;
  2049.   }
  2050.   return rsult;
  2051. #endif
  2052. #ifdef WIN_X
  2053.   Nlm_Int2  rsult;
  2054.  
  2055.   rsult = 0;
  2056.   if (Nlm_GetTextMetrics ()) {
  2057.     rsult = fontInfo.max_bounds.width;
  2058.   }
  2059.   return rsult;
  2060. #endif
  2061. }
  2062.  
  2063. extern void Nlm_SetPen (Nlm_PoinT pt)
  2064.  
  2065. {
  2066. #ifdef WIN_MAC
  2067.   MoveTo (pt.x, pt.y);
  2068. #endif
  2069. #ifdef WIN_MSWIN
  2070.   if (Nlm_currentHDC != NULL) {
  2071.     MoveToEx (Nlm_currentHDC, pt.x, pt.y, NULL);
  2072.   }
  2073. #endif
  2074. #ifdef WIN_X
  2075.   currentPoint = pt;
  2076. #endif
  2077. }
  2078.  
  2079. extern void Nlm_GetPen (Nlm_PointPtr pt)
  2080.  
  2081. {
  2082. #ifdef WIN_MAC
  2083.   Nlm_PointTool  ptool;
  2084.  
  2085.   if (pt != NULL) {
  2086.     GetPen (&ptool);
  2087.     Nlm_PointToolToPoinT (ptool, pt);
  2088.   }
  2089. #endif
  2090. #ifdef WIN_MSWIN
  2091.   POINT  pos;
  2092.  
  2093.   if (pt != NULL && Nlm_currentHDC != NULL) {
  2094.     GetCurrentPositionEx (Nlm_currentHDC, &pos);
  2095.     pt->x = (Nlm_Int2) pos.x;
  2096.     pt->y = (Nlm_Int2) pos.y;
  2097.   }
  2098. #endif
  2099. #ifdef WIN_X
  2100.   if (pt != NULL) {
  2101.     *pt = currentPoint;
  2102.   }
  2103. #endif
  2104. }
  2105.  
  2106. #ifdef DCLAP
  2107. extern void Nlm_TextOpaque()
  2108. {
  2109. #ifdef WIN_MAC
  2110.   /* TextMode (srcCopy); */
  2111. #endif
  2112. #ifdef WIN_MSWIN
  2113.   if (Nlm_currentHDC != NULL) SetBkMode (Nlm_currentHDC, OPAQUE);
  2114. #endif
  2115. #ifdef WIN_X
  2116. #endif
  2117. }
  2118.  
  2119. extern void Nlm_TextTransparent()
  2120. {
  2121. #ifdef WIN_MAC
  2122.   /* TextMode (srcOr); */
  2123. #endif
  2124. #ifdef WIN_MSWIN
  2125.   if (Nlm_currentHDC != NULL) SetBkMode (Nlm_currentHDC, TRANSPARENT);
  2126. #endif
  2127. #ifdef WIN_X
  2128. #endif
  2129. }
  2130.  
  2131. #endif
  2132.  
  2133.  
  2134. extern void Nlm_PaintChar (Nlm_Char ch)
  2135.  
  2136. {
  2137. #ifdef WIN_MAC
  2138.   DrawChar (ch);
  2139. #endif
  2140. #ifdef WIN_MSWIN
  2141.   Nlm_PoinT  pt;
  2142.   Nlm_Char   str [2];
  2143.  
  2144.   if (Nlm_currentHDC != NULL) {
  2145.     str [0] = ch;
  2146.     str [1] = '\0';
  2147.     Nlm_GetPen (&pt);
  2148.     TextOut (Nlm_currentHDC, pt.x, pt.y - Nlm_Ascent (), str, 1);
  2149.     pt.x += Nlm_CharWidth (ch);
  2150.     Nlm_MoveTo (pt.x, pt.y);
  2151.   }
  2152. #endif
  2153. #ifdef WIN_X
  2154.   Nlm_PoinT  pt;
  2155.   Nlm_Char   str [2];
  2156.  
  2157.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  2158.       Nlm_currentXGC != NULL) {
  2159.     str [0] = ch;
  2160.     str [1] = '\0';
  2161.     Nlm_GetPen (&pt);
  2162.     XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2163.                  pt.x - Nlm_XOffset, pt.y - Nlm_YOffset, str, 1);
  2164.     pt.x += Nlm_CharWidth (ch);
  2165.     Nlm_MoveTo (pt.x, pt.y);
  2166.   }
  2167. #endif
  2168. }
  2169.  
  2170. extern void Nlm_PaintString (Nlm_CharPtr text)
  2171.  
  2172. {
  2173. #ifdef WIN_MAC
  2174.   Nlm_PoinT  pt;
  2175.   Nlm_Char   str [256];
  2176.  
  2177.   if (text != NULL) {
  2178.     Nlm_GetPen (&pt);
  2179. #ifdef DCLAP
  2180.        if (*text) drawstring ( text);
  2181. #else
  2182.     if (Nlm_StringLen (text) > 0) {
  2183.       Nlm_StringNCpy (str, text, sizeof (str));
  2184.       Nlm_CtoPstr (str);
  2185.       DrawString ((StringPtr) str);
  2186.     }
  2187. #endif
  2188.     pt.x += Nlm_StringWidth (text);
  2189.     Nlm_MoveTo (pt.x, pt.y);
  2190.   }
  2191. #endif
  2192. #ifdef WIN_MSWIN
  2193.   Nlm_Int2   len;
  2194.   Nlm_PoinT  pt;
  2195.  
  2196.   if (text != NULL && Nlm_currentHDC != NULL) {
  2197.     len = (Nlm_Int2) Nlm_StringLen (text);
  2198.     Nlm_GetPen (&pt);
  2199.     if (len > 0) {
  2200.       TextOut (Nlm_currentHDC, pt.x, pt.y - Nlm_Ascent (), text, len);
  2201.     }
  2202.     pt.x += Nlm_StringWidth (text);
  2203.     Nlm_MoveTo (pt.x, pt.y);
  2204.   }
  2205. #endif
  2206. #ifdef WIN_X
  2207.   Nlm_Int2   len;
  2208.   Nlm_PoinT  pt;
  2209.  
  2210.   if (text != NULL && Nlm_currentXDisplay != NULL &&
  2211.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2212.     len = (Nlm_Int2) Nlm_StringLen (text);
  2213.     Nlm_GetPen (&pt);
  2214.     if (len > 0) {
  2215.       XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2216.                    pt.x - Nlm_XOffset, pt.y - Nlm_YOffset, text, len);
  2217.     }
  2218.     pt.x += Nlm_StringWidth (text);
  2219.     Nlm_MoveTo (pt.x, pt.y);
  2220.   }
  2221. #endif
  2222. }
  2223.  
  2224. #ifdef VAR_ARGS
  2225. void CDECL Nlm_PaintText (format, va_alist)
  2226.   char *format;
  2227.   va_dcl
  2228. #else
  2229. void CDECL Nlm_PaintText (char *format, ...)
  2230. #endif
  2231.  
  2232. {
  2233. #ifdef WIN_MAC
  2234.   va_list    args;
  2235.   Nlm_PoinT  pt;
  2236.   Nlm_Char   str [256];
  2237.  
  2238.   if (format != NULL) {
  2239. #ifdef VAR_ARGS
  2240.     va_start(args);
  2241. #else
  2242.     va_start(args, format);
  2243. #endif
  2244.     vsprintf(str, format, args);
  2245.     va_end(args);
  2246.     Nlm_GetPen (&pt);
  2247.     if (Nlm_StringLen (str) > 0) {
  2248.       Nlm_CtoPstr (str);
  2249.       DrawString ((StringPtr) str);
  2250.     }
  2251.     pt.y += Nlm_LineHeight ();
  2252.     Nlm_MoveTo (pt.x, pt.y);
  2253.   }
  2254. #endif
  2255. #ifdef WIN_MSWIN
  2256.   va_list    args;
  2257.   Nlm_Int2   len;
  2258.   Nlm_PoinT  pt;
  2259.   Nlm_Char   str [256];
  2260.  
  2261.   if (format != NULL && Nlm_currentHDC != NULL) {
  2262. #ifdef VAR_ARGS
  2263.     va_start(args);
  2264. #else
  2265.     va_start(args, format);
  2266. #endif
  2267.     vsprintf(str, format, args);
  2268.     va_end(args);
  2269.     len = (Nlm_Int2) Nlm_StringLen (str);
  2270.     Nlm_GetPen (&pt);
  2271.     if (len > 0) {
  2272.       TextOut (Nlm_currentHDC, pt.x, pt.y - Nlm_Ascent (), str, len);
  2273.     }
  2274.     pt.y += Nlm_LineHeight ();
  2275.     Nlm_MoveTo (pt.x, pt.y);
  2276.   }
  2277. #endif
  2278. #ifdef WIN_X
  2279.   va_list    args;
  2280.   Nlm_Int2   len;
  2281.   Nlm_PoinT  pt;
  2282.   Nlm_Char   str [256];
  2283.  
  2284.   if (format != NULL && Nlm_currentXDisplay != NULL &&
  2285.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2286. #ifdef VAR_ARGS
  2287.     va_start(args);
  2288. #else
  2289.     va_start(args, format);
  2290. #endif
  2291.     vsprintf(str, format, args);
  2292.     va_end(args);
  2293.     len = (Nlm_Int2) Nlm_StringLen (str);
  2294.     Nlm_GetPen (&pt);
  2295.     if (len > 0) {
  2296.       XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2297.                    pt.x - Nlm_XOffset, pt.y - Nlm_YOffset, str, len);
  2298.     }
  2299.     pt.y += Nlm_LineHeight ();
  2300.     Nlm_MoveTo (pt.x, pt.y);
  2301.   }
  2302. #endif
  2303. }
  2304.  
  2305. extern void Nlm_DrawString (Nlm_RectPtr r, Nlm_CharPtr text,
  2306.                             Nlm_Char jst, Nlm_Boolean gray)
  2307.  
  2308. {
  2309.   Nlm_DrawText (r, text, Nlm_StringLen (text), jst, gray);
  2310. }
  2311.  
  2312. extern void Nlm_DrawText (Nlm_RectPtr r, Nlm_CharPtr text,
  2313.                           Nlm_sizeT len, Nlm_Char jst,
  2314.                           Nlm_Boolean gray)
  2315.  
  2316. {
  2317. #ifdef WIN_MAC
  2318.   Nlm_Int2      delta;
  2319.   Nlm_Int2      height;
  2320.   Nlm_Int2      just;
  2321.   Nlm_Int2      limit;
  2322.   PenState      pnState;
  2323.   Nlm_RectTool  rtool;
  2324.  
  2325.   if (r != NULL) {
  2326.     Nlm_EraseRect (r);
  2327.     if (text != NULL && len > 0) {
  2328.       Nlm_RecTToRectTool (r, &rtool);
  2329.       limit = ABS (r->bottom - r->top);
  2330.       height = Nlm_LineHeight ();
  2331.       delta = limit - height;
  2332.       if (delta > 0) {
  2333.         rtool.top += delta / 2;
  2334.         rtool.bottom = rtool.top + height;
  2335.       }
  2336.       switch (jst) {
  2337.         case 'r':
  2338.           just = -1;
  2339.           break;
  2340.         case 'l':
  2341.           just = 0;
  2342.           break;
  2343.         case 'c':
  2344.           just = 1;
  2345.           break;
  2346.         default:
  2347.           just = 0;
  2348.           break;
  2349.       }
  2350.       TextBox (text, len, &rtool, just);
  2351.       if (gray) {
  2352.         GetPenState (&pnState);
  2353.         PenMode (patBic);
  2354.         PenPat ((ConstPatternParam) grayPat);
  2355.         PaintRect (&rtool);
  2356.         SetPenState (&pnState);
  2357.       }
  2358.     }
  2359.   }
  2360. #endif
  2361. #ifdef WIN_MSWIN
  2362.   Nlm_Int2      format;
  2363.   Nlm_Int4      oldcolor;
  2364.   Nlm_RectTool  rtool;
  2365.  
  2366.   if (r != NULL && Nlm_currentHDC != NULL) {
  2367.     Nlm_RecTToRectTool (r, &rtool);
  2368.     if (Nlm_currentHWnd != NULL) {
  2369.       Nlm_EraseRect (r);
  2370.     } else {
  2371.       FillRect (Nlm_currentHDC, &rtool, hWhiteBrush);
  2372.     }
  2373.     if (text != NULL && len > 0) {
  2374.       switch (jst) {
  2375.         case 'r':
  2376.           format = DT_RIGHT;
  2377.           break;
  2378.         case 'l':
  2379.           format = DT_LEFT;
  2380.           break;
  2381.         case 'c':
  2382.           format = DT_CENTER;
  2383.           break;
  2384.         default:
  2385.           format = DT_LEFT;
  2386.           break;
  2387.       }
  2388.       if (gray) {
  2389.         oldcolor = SetTextColor (Nlm_currentHDC, GetSysColor (COLOR_GRAYTEXT));
  2390.       }
  2391.       DrawText (Nlm_currentHDC, text, (Nlm_Int2) len, &rtool,
  2392.                 format | DT_VCENTER | DT_NOPREFIX);
  2393.       if (gray) {
  2394.         SetTextColor (Nlm_currentHDC, oldcolor);
  2395.       }
  2396.     }
  2397.   }
  2398. #endif
  2399. #ifdef WIN_X
  2400.   Nlm_Int2   delta;
  2401.   Nlm_Int2   height;
  2402.   Nlm_Int2   limit;
  2403.   Pixmap     pix;
  2404.   Nlm_PoinT  pt;
  2405.   Nlm_Int2   width;
  2406.  
  2407.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  2408.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2409.     Nlm_EraseRect (r);
  2410.     if (text != NULL && len > 0) {
  2411.       pt.x = r->left;
  2412.       pt.y = r->top;
  2413.       limit = ABS (r->right - r->left);
  2414.       width = Nlm_TextWidth (text, len);
  2415.       while (len > 0 && width > limit) {
  2416.         len--;
  2417.         width = Nlm_TextWidth (text, len);
  2418.       }
  2419.       delta = limit - width;
  2420.       switch (jst) {
  2421.         case 'r':
  2422.           pt.x += delta;
  2423.           break;
  2424.         case 'l':
  2425.           break;
  2426.         case 'c':
  2427.           pt.x += delta / 2;
  2428.           break;
  2429.         default:
  2430.           break;
  2431.       }
  2432.       limit = ABS (r->bottom - r->top);
  2433.       height = Nlm_LineHeight ();
  2434.       delta = limit - height;
  2435.       if (delta > 0) {
  2436.         pt.y += delta / 2;
  2437.       }
  2438.       if (limit >= height) {
  2439.         if (gray) {
  2440.           pix = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  2441.                                        (char *) grayPat, 8, 8);
  2442.           if (pix != 0 && Nlm_currentXGC != NULL) {
  2443.             XSetStipple (Nlm_currentXDisplay, Nlm_currentXGC, pix);
  2444.           }
  2445.         }
  2446.         XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2447.                      pt.x - Nlm_XOffset, pt.y + Nlm_Ascent () - Nlm_YOffset,
  2448.                      text, (int) len);
  2449.         if (gray && pix != 0) {
  2450.           XFreePixmap (Nlm_currentXDisplay, pix);
  2451.           if (Nlm_currentXGC != NULL) {
  2452.             XSetStipple (Nlm_currentXDisplay, Nlm_currentXGC, currentPixmap);
  2453.           }
  2454.         }
  2455.       }
  2456.     }
  2457.   }
  2458. #endif
  2459. }
  2460.  
  2461. extern void Nlm_MoveTo (Nlm_Int2 x, Nlm_Int2 y)
  2462.  
  2463. {
  2464. #ifdef WIN_MAC
  2465.   MoveTo (x, y);
  2466. #endif
  2467. #ifdef WIN_MSWIN
  2468.   if (Nlm_currentHDC != NULL) {
  2469.     MoveToEx (Nlm_currentHDC, x, y, NULL);
  2470.   }
  2471. #endif
  2472. #ifdef WIN_X
  2473.   currentPoint.x = x;
  2474.   currentPoint.y = y;
  2475. #endif
  2476. }
  2477.  
  2478. extern void Nlm_LineTo (Nlm_Int2 x, Nlm_Int2 y)
  2479.  
  2480. {
  2481. #ifdef WIN_MAC
  2482.   LineTo (x, y);
  2483. #endif
  2484. #ifdef WIN_MSWIN
  2485.   if (Nlm_currentHDC != NULL) {
  2486.     SetBkMode (Nlm_currentHDC, TRANSPARENT);
  2487.     LineTo (Nlm_currentHDC, x, y);
  2488.     SetBkMode (Nlm_currentHDC, OPAQUE);
  2489.   }
  2490. #endif
  2491. #ifdef WIN_X
  2492.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  2493.       Nlm_currentXGC != NULL) {
  2494.     XDrawLine (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2495.                currentPoint.x - Nlm_XOffset, currentPoint.y - Nlm_YOffset,
  2496.                x - Nlm_XOffset, y - Nlm_YOffset);
  2497.     currentPoint.x = x;
  2498.     currentPoint.y = y;
  2499.   }
  2500. #endif
  2501. }
  2502.  
  2503. extern void Nlm_DrawLine (Nlm_PoinT pt1, Nlm_PoinT pt2)
  2504.  
  2505. {
  2506. #ifdef WIN_MAC
  2507.   MoveTo (pt1.x, pt1.y);
  2508.   LineTo (pt2.x, pt2.y);
  2509. #endif
  2510. #ifdef WIN_MSWIN
  2511.   if (Nlm_currentHDC != NULL) {
  2512.     MoveToEx (Nlm_currentHDC, pt1.x, pt1.y, NULL);
  2513.     SetBkMode (Nlm_currentHDC, TRANSPARENT);
  2514.     LineTo (Nlm_currentHDC, pt2.x, pt2.y);
  2515.     SetBkMode (Nlm_currentHDC, OPAQUE);
  2516.   }
  2517. #endif
  2518. #ifdef WIN_X
  2519.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  2520.       Nlm_currentXGC != NULL) {
  2521.     XDrawLine (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2522.                pt1.x - Nlm_XOffset, pt1.y - Nlm_YOffset,
  2523.                pt2.x - Nlm_XOffset, pt2.y - Nlm_YOffset);
  2524.     currentPoint.x = pt2.x;
  2525.     currentPoint.y = pt2.y;
  2526.   }
  2527. #endif
  2528. }
  2529.  
  2530. extern void Nlm_LoadPt (Nlm_PointPtr pt, Nlm_Int2 x, Nlm_Int2 y)
  2531.  
  2532. {
  2533.   if (pt != NULL) {
  2534.     pt->x = x;
  2535.     pt->y = y;
  2536.   }
  2537. }
  2538.  
  2539. extern void Nlm_AddPt (Nlm_PoinT src, Nlm_PointPtr dst)
  2540.  
  2541. {
  2542.   if (dst != NULL) {
  2543.     dst->x += src.x;
  2544.     dst->y += src.y;
  2545.   }
  2546. }
  2547.  
  2548. extern void Nlm_SubPt (Nlm_PoinT src, Nlm_PointPtr dst)
  2549.  
  2550. {
  2551.   if (dst != NULL) {
  2552.     dst->x -= src.x;
  2553.     dst->y -= src.y;
  2554.   }
  2555. }
  2556.  
  2557. extern Nlm_Boolean Nlm_EqualPt (Nlm_PoinT p1, Nlm_PoinT p2)
  2558.  
  2559. {
  2560.   return (Nlm_Boolean) (p1.x == p2.x && p1.y == p2.y);
  2561. }
  2562.  
  2563. extern Nlm_Boolean Nlm_PtInRect (Nlm_PoinT pt, Nlm_RectPtr r)
  2564.  
  2565. {
  2566.   return (Nlm_Boolean) (r != NULL && pt.x >= r->left && pt.x < r->right &&
  2567.                         pt.y >= r->top && pt.y < r->bottom);
  2568. }
  2569.  
  2570. extern Nlm_Boolean Nlm_PtInRgn (Nlm_PoinT pt, Nlm_RegioN rgn)
  2571.  
  2572. {
  2573.   Nlm_RgnTool    ntool;
  2574.   Nlm_Boolean    rsult;
  2575. #ifdef WIN_MAC
  2576.   Nlm_PointTool  ptool;
  2577. #endif
  2578.  
  2579.   rsult = FALSE;
  2580.   if (rgn != NULL) {
  2581.     ntool = (Nlm_RgnTool) rgn;
  2582. #ifdef WIN_MAC
  2583.     Nlm_PoinTToPointTool (pt, &ptool);
  2584.     rsult = PtInRgn (ptool, ntool);
  2585. #endif
  2586. #ifdef WIN_MSWIN
  2587.     rsult = (Nlm_Boolean) PtInRegion (ntool, pt.x, pt.y);
  2588. #endif
  2589. #ifdef WIN_X
  2590.     rsult = (XPointInRegion (ntool, pt.x, pt.y) != 0);
  2591. #endif
  2592.   }
  2593.   return rsult;
  2594. }
  2595.  
  2596. extern void Nlm_LoadRect (Nlm_RectPtr r, Nlm_Int2 lf,
  2597.                           Nlm_Int2 tp, Nlm_Int2 rt,
  2598.                           Nlm_Int2 bt)
  2599.  
  2600. {
  2601.   if (r != NULL) {
  2602.     r->left = lf;
  2603.     r->top = tp;
  2604.     r->right = rt;
  2605.     r->bottom = bt;
  2606.   }
  2607. }
  2608.  
  2609. extern void Nlm_UpsetRect (Nlm_RectPtr r, Nlm_Int2 lf,
  2610.                            Nlm_Int2 tp, Nlm_Int2 rt,
  2611.                            Nlm_Int2 bt)
  2612.  
  2613. {
  2614.   if (r != NULL) {
  2615.     r->left += lf;
  2616.     r->top += tp;
  2617.     r->right -= rt;
  2618.     r->bottom -= bt;
  2619.   }
  2620. }
  2621.  
  2622. extern void Nlm_OffsetRect (Nlm_RectPtr r, Nlm_Int2 dx, Nlm_Int2 dy)
  2623.  
  2624. {
  2625.   if (r != NULL) {
  2626.     r->left += dx;
  2627.     r->top += dy;
  2628.     r->right += dx;
  2629.     r->bottom += dy;
  2630.   }
  2631. }
  2632.  
  2633. extern void Nlm_InsetRect (Nlm_RectPtr r, Nlm_Int2 dx, Nlm_Int2 dy)
  2634.  
  2635. {
  2636.   if (r != NULL) {
  2637.     r->left += dx;
  2638.     r->top += dy;
  2639.     r->right -= dx;
  2640.     r->bottom -= dy;
  2641.   }
  2642. }
  2643.  
  2644. static void Nlm_LoadNormalized (Nlm_RectPtr dst, Nlm_RectPtr src)
  2645.  
  2646. {
  2647.   if (src != NULL && dst != NULL) {
  2648.     Nlm_LoadRect (dst, MIN (src->left, src->right), MIN (src->top, src->bottom),
  2649.                   MAX (src->left, src->right), MAX (src->top, src->bottom));
  2650.   }
  2651. }
  2652.  
  2653. extern Nlm_Boolean Nlm_SectRect (Nlm_RectPtr src1, Nlm_RectPtr src2,
  2654.                                  Nlm_RectPtr dst)
  2655.  
  2656. {
  2657.   Nlm_Boolean   rsult;
  2658.   Nlm_RectTool  rtool1;
  2659.   Nlm_RectTool  rtool2;
  2660.   Nlm_RectTool  rtool3;
  2661. #ifdef WIN_X
  2662.   Nlm_RecT      rct1;
  2663.   Nlm_RecT      rct2;
  2664. #endif
  2665.  
  2666.   rsult = FALSE;
  2667.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  2668. #ifdef WIN_MAC
  2669.     Nlm_RecTToRectTool (src1, &rtool1);
  2670.     Nlm_RecTToRectTool (src2, &rtool2);
  2671.     rsult = SectRect (&rtool1, &rtool2, &rtool3);
  2672.     Nlm_RectToolToRecT (&rtool3, dst);
  2673. #endif
  2674. #ifdef WIN_MSWIN
  2675.     Nlm_RecTToRectTool (src1, &rtool1);
  2676.     Nlm_RecTToRectTool (src2, &rtool2);
  2677.     rsult = (Nlm_Boolean) IntersectRect (&rtool3, &rtool1, &rtool2);
  2678.     Nlm_RectToolToRecT (&rtool3, dst);
  2679. #endif
  2680. #ifdef WIN_X
  2681.     Nlm_LoadNormalized (&rct1, src1);
  2682.     Nlm_LoadNormalized (&rct2, src2);
  2683.     dst->left = MAX (rct1.left, rct2.left);
  2684.     dst->right = MIN (rct1.right, rct2.right);
  2685.     dst->top = MAX (rct1.top, rct2.top);
  2686.     dst->bottom = MIN (rct1.bottom, rct2.bottom);
  2687.     if (dst->left > dst->right || dst->top > dst->bottom) {
  2688.       Nlm_LoadRect (dst, 0, 0, 0, 0);
  2689.       }
  2690. #ifdef DCLAP
  2691.     /* ! NEED rsult ! */
  2692.     rsult= ( (rct1.left >= rct2.left && rct1.left <= rct2.right)
  2693.                 || (rct1.right >= rct2.left && rct1.right <= rct2.right) )
  2694.                 && 
  2695.               ( (rct1.top >= rct2.top && rct1.top <= rct2.bottom)
  2696.                 || (rct1.bottom >= rct2.top && rct1.bottom <= rct2.bottom) );
  2697. #endif
  2698. #endif
  2699.   }
  2700.   return rsult;
  2701. }
  2702.  
  2703. extern Nlm_Boolean Nlm_UnionRect (Nlm_RectPtr src1, Nlm_RectPtr src2,
  2704.                                   Nlm_RectPtr dst)
  2705.  
  2706. {
  2707.   Nlm_Boolean   rsult;
  2708.   Nlm_RectTool  rtool1;
  2709.   Nlm_RectTool  rtool2;
  2710.   Nlm_RectTool  rtool3;
  2711. #ifdef WIN_X
  2712.   Nlm_RecT      rct1;
  2713.   Nlm_RecT      rct2;
  2714. #endif
  2715.  
  2716.   rsult = FALSE;
  2717.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  2718. #ifdef WIN_MAC
  2719.     Nlm_RecTToRectTool (src1, &rtool1);
  2720.     Nlm_RecTToRectTool (src2, &rtool2);
  2721.     UnionRect (&rtool1, &rtool2, &rtool3);
  2722.     rsult = EmptyRect (&rtool3);
  2723.     Nlm_RectToolToRecT (&rtool3, dst);
  2724. #endif
  2725. #ifdef WIN_MSWIN
  2726.     Nlm_RecTToRectTool (src1, &rtool1);
  2727.     Nlm_RecTToRectTool (src2, &rtool2);
  2728.     rsult = (Nlm_Boolean) UnionRect (&rtool3, &rtool1, &rtool2);
  2729.     Nlm_RectToolToRecT (&rtool3, dst);
  2730. #endif
  2731. #ifdef WIN_X
  2732.     Nlm_LoadNormalized (&rct1, src1);
  2733.     Nlm_LoadNormalized (&rct2, src2);
  2734.     dst->left = MIN (rct1.left, rct2.left);
  2735.     dst->right = MAX (rct1.right, rct2.right);
  2736.     dst->top = MIN (rct1.top, rct2.top);
  2737.     dst->bottom = MAX (rct1.bottom, rct2.bottom);
  2738. #endif
  2739.   }
  2740.   return rsult;
  2741. }
  2742.  
  2743. extern Nlm_Boolean Nlm_EqualRect (Nlm_RectPtr r1, Nlm_RectPtr r2)
  2744.  
  2745. {
  2746.   return (Nlm_Boolean) (r1 != NULL && r2 != NULL && r1->left == r2->left &&
  2747.                         r1->top == r2->top && r1->right == r2->right &&
  2748.                         r1->bottom == r2->bottom);
  2749. }
  2750.  
  2751. extern Nlm_Boolean Nlm_EmptyRect (Nlm_RectPtr r)
  2752.  
  2753. {
  2754.   return (Nlm_Boolean) ! (r != NULL && r->bottom > r->top && r->right > r->left);
  2755. }
  2756.  
  2757. extern Nlm_Boolean Nlm_RectInRect (Nlm_RectPtr r1, Nlm_RectPtr r2)
  2758.  
  2759. {
  2760.   Nlm_Boolean  rsult;
  2761.  
  2762.   rsult = FALSE;
  2763.   if (r1 != NULL && r2 != NULL &&
  2764.     r1->top >= r2->top && r1->bottom <= r2->bottom &&
  2765.     r1->left >= r2->left && r1->right <= r2->right) {
  2766.     rsult = TRUE;
  2767.   }
  2768.   return rsult;
  2769. }
  2770.  
  2771. extern Nlm_Boolean Nlm_RectInRgn (Nlm_RectPtr r, Nlm_RegioN rgn)
  2772.  
  2773. {
  2774.   Nlm_RgnTool   ntool;
  2775.   Nlm_Boolean   rsult;
  2776.   Nlm_RectTool  rtool;
  2777.  
  2778.   rsult = FALSE;
  2779.   if (r != NULL && rgn != NULL) {
  2780.     Nlm_RecTToRectTool (r, &rtool);
  2781.     ntool = (Nlm_RgnTool) rgn;
  2782. #ifdef WIN_MAC
  2783.     rsult = RectInRgn (&rtool, ntool);
  2784. #endif
  2785. #ifdef WIN_MSWIN
  2786.     rsult = (Nlm_Boolean) RectInRegion (ntool, &rtool);
  2787. #endif
  2788. #ifdef WIN_X
  2789.     rsult = (XRectInRegion (ntool, rtool.x, rtool.y, rtool.width, rtool.height) != 0);
  2790. #endif
  2791.   }
  2792.   return rsult;
  2793. }
  2794.  
  2795. extern void Nlm_EraseRect (Nlm_RectPtr r)
  2796.  
  2797. {
  2798. #ifdef WIN_MAC
  2799.   Nlm_RectTool  rtool;
  2800.  
  2801.   if (r != NULL) {
  2802.     Nlm_RecTToRectTool (r, &rtool);
  2803.     EraseRect (&rtool);
  2804.   }
  2805. #endif
  2806. #ifdef WIN_MSWIN
  2807.   Nlm_Int4      bkColor;
  2808.   HBRUSH        hBackBrush;
  2809.   Nlm_RectTool  rtool;
  2810.  
  2811.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  2812.     Nlm_RecTToRectTool (r, &rtool);
  2813.     bkColor = GetBkColor (Nlm_currentHDC);
  2814.     hBackBrush = CreateSolidBrush (bkColor);
  2815.     FillRect (Nlm_currentHDC, &rtool, hBackBrush);
  2816.     DeleteObject (hBackBrush);
  2817.   }
  2818. #endif
  2819. #ifdef WIN_X
  2820.   Nlm_RectTool  rtool;
  2821.  
  2822.   if (r != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0) {
  2823.     Nlm_RecTToRectTool (r, &rtool);
  2824.     XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  2825.     XFillRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2826.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  2827.                     rtool.width, rtool.height);
  2828.     XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentFgColor);
  2829.   }
  2830. #endif
  2831. }
  2832.  
  2833. extern void Nlm_FrameRect (Nlm_RectPtr r)
  2834.  
  2835. {
  2836. #ifdef WIN_MAC
  2837.   Nlm_RectTool  rtool;
  2838.  
  2839.   if (r != NULL) {
  2840.     Nlm_RecTToRectTool (r, &rtool);
  2841.     if (rtool.right == rtool.left) {
  2842.       rtool.right = rtool.left + 1;
  2843.     }
  2844.     if (rtool.bottom == rtool.top) {
  2845.       rtool.bottom = rtool.top + 1;
  2846.     }
  2847.     FrameRect (&rtool);
  2848.   }
  2849. #endif
  2850. #ifdef WIN_MSWIN
  2851.   HBRUSH        oldBrush;
  2852.   Nlm_RectTool  rtool;
  2853.  
  2854.   if (r != NULL && Nlm_currentHDC != NULL) {
  2855.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (NULL_BRUSH));
  2856.     Nlm_RecTToRectTool (r, &rtool);
  2857.     if (rtool.right == rtool.left) {
  2858.       rtool.right = rtool.left + 1;
  2859.     }
  2860.     if (rtool.bottom == rtool.top) {
  2861.       rtool.bottom = rtool.top + 1;
  2862.     }
  2863.     Rectangle (Nlm_currentHDC, rtool.left, rtool.top, rtool.right, rtool.bottom);
  2864.     if (oldBrush != NULL) {
  2865.       SelectObject (Nlm_currentHDC, oldBrush);
  2866.     }
  2867.   }
  2868. #endif
  2869. #ifdef WIN_X
  2870.   Nlm_RectTool  rtool;
  2871.  
  2872.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  2873.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2874.     Nlm_RecTToRectTool (r, &rtool);
  2875.     rtool.width = MAX (rtool.width, 1);
  2876.     rtool.height = MAX (rtool.height, 1);
  2877.     XDrawRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2878.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  2879.                     rtool.width - 1, rtool.height - 1);
  2880.   }
  2881. #endif
  2882. }
  2883.  
  2884. extern void Nlm_PaintRect (Nlm_RectPtr r)
  2885.  
  2886. {
  2887. #ifdef WIN_MAC
  2888.   Nlm_RectTool  rtool;
  2889.  
  2890.   if (r != NULL) {
  2891.     Nlm_RecTToRectTool (r, &rtool);
  2892.     if (rtool.right == rtool.left) {
  2893.       rtool.right = rtool.left + 1;
  2894.     }
  2895.     if (rtool.bottom == rtool.top) {
  2896.       rtool.bottom = rtool.top + 1;
  2897.     }
  2898.     PaintRect (&rtool);
  2899.   }
  2900. #endif
  2901. #ifdef WIN_MSWIN
  2902.   HPEN          oldPen;
  2903.   Nlm_RectTool  rtool;
  2904.  
  2905.   if (r != NULL && Nlm_currentHDC != NULL) {
  2906.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  2907.     Nlm_RecTToRectTool (r, &rtool);
  2908.     if (rtool.right == rtool.left) {
  2909.       rtool.right = rtool.left + 1;
  2910.     }
  2911.     if (rtool.bottom == rtool.top) {
  2912.       rtool.bottom = rtool.top + 1;
  2913.     }
  2914.     Rectangle (Nlm_currentHDC, rtool.left, rtool.top, rtool.right, rtool.bottom);
  2915.     if (oldPen != NULL) {
  2916.       SelectObject (Nlm_currentHDC, oldPen);
  2917.     }
  2918.   }
  2919. #endif
  2920. #ifdef WIN_X
  2921.   Nlm_RectTool  rtool;
  2922.  
  2923.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  2924.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2925.     Nlm_RecTToRectTool (r, &rtool);
  2926.     rtool.width = MAX (rtool.width, 1);
  2927.     rtool.height = MAX (rtool.height, 1);
  2928.     XFillRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2929.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  2930.                     rtool.width, rtool.height);
  2931.   }
  2932. #endif
  2933. }
  2934.  
  2935. extern void Nlm_InvertRect (Nlm_RectPtr r)
  2936.  
  2937. {
  2938. #ifdef WIN_MAC
  2939.   Nlm_RectTool  rtool;
  2940.  
  2941.   if (r != NULL) {
  2942.     Nlm_RecTToRectTool (r, &rtool);
  2943.     InvertRect (&rtool);
  2944.   }
  2945. #endif
  2946. #ifdef WIN_MSWIN
  2947.   Nlm_RectTool  rtool;
  2948.  
  2949.   if (r != NULL && Nlm_currentHDC != NULL) {
  2950.     Nlm_RecTToRectTool (r, &rtool);
  2951.     InvertRect (Nlm_currentHDC, &rtool);
  2952.   }
  2953. #endif
  2954. #ifdef WIN_X
  2955.   Nlm_RectTool  rtool;
  2956.  
  2957.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  2958.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2959.     Nlm_RecTToRectTool (r, &rtool);
  2960. #ifndef no_DCLAP
  2961.     if (hasColor) {
  2962.       XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXequiv);
  2963.     } else
  2964. #endif 
  2965.     {
  2966.       XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXinvert);
  2967.     }
  2968.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, FillStippled);
  2969.     XFillRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2970.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  2971.                     rtool.width, rtool.height);
  2972.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  2973.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  2974.   }
  2975. #endif
  2976. }
  2977.  
  2978. extern void Nlm_ScrollRect (Nlm_RectPtr r, Nlm_Int2 dx, Nlm_Int2 dy)
  2979.  
  2980. {
  2981. #ifdef WIN_MAC
  2982.   Nlm_RectTool  rtool;
  2983.  
  2984.   if (r != NULL) {
  2985.     Nlm_RecTToRectTool (r, &rtool);
  2986.     ScrollRect (&rtool, dx, dy, (Nlm_RgnTool) Nlm_scrollRgn);
  2987.     InvalRgn ((Nlm_RgnTool) Nlm_scrollRgn);
  2988.   }
  2989. #endif
  2990. #ifdef WIN_MSWIN
  2991.   Nlm_RectTool  rtool;
  2992.  
  2993.   if (r != NULL && Nlm_currentHDC != NULL) {
  2994.     SetRectRgn ((Nlm_RgnTool) Nlm_scrollRgn, 0, 0, 0, 0);
  2995.     Nlm_RecTToRectTool (r, &rtool);
  2996.     ScrollDC (Nlm_currentHDC, dx, dy, &rtool, &rtool,
  2997.               (Nlm_RgnTool) Nlm_scrollRgn, NULL);
  2998.     if (Nlm_currentHWnd != NULL && Nlm_scrollRgn != NULL) {
  2999.       FillRgn (Nlm_currentHDC, (Nlm_RgnTool) Nlm_scrollRgn,
  3000.                GetBackgroundBrush (Nlm_currentHWnd));
  3001.     }
  3002.     InvalidateRgn (Nlm_currentHWnd, (Nlm_RgnTool) Nlm_scrollRgn, TRUE);
  3003.   }
  3004. #endif
  3005. #ifdef WIN_X
  3006.   XEvent        event;
  3007.   unsigned int  height;
  3008.   Nlm_RecT      rct;
  3009.   Nlm_RectTool  rtool;
  3010.   unsigned int  width;
  3011.   unsigned int  dstX;
  3012.   unsigned int  dstY;
  3013.   unsigned int  srcX;
  3014.   unsigned int  srcY;
  3015.  
  3016.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3017.       Nlm_currentXGC != NULL && Nlm_currentXWindow != 0) {
  3018.     height = ABS (r->bottom - r->top) - ABS (dy);
  3019.     width = ABS (r->right - r->left) - ABS (dx);
  3020.     if (dx > 0) {
  3021.       srcX = r->left - Nlm_XOffset;
  3022.       dstX = r->left - Nlm_XOffset + dx;
  3023.     } else if (dx < 0) {
  3024.       srcX = r->left - Nlm_XOffset - dx;
  3025.       dstX = r->left - Nlm_XOffset;
  3026.     } else {
  3027.       srcX = r->left - Nlm_XOffset;
  3028.       dstX = r->left - Nlm_XOffset;
  3029.     }
  3030.     if (dy > 0) {
  3031.       srcY = r->top - Nlm_YOffset;
  3032.       dstY = r->top - Nlm_YOffset + dy;
  3033.     } else if (dy < 0) {
  3034.       srcY = r->top - Nlm_YOffset - dy;
  3035.       dstY = r->top - Nlm_YOffset;
  3036.     } else {
  3037.       srcY = r->top - Nlm_YOffset;
  3038.       dstY = r->top - Nlm_YOffset;
  3039.     }
  3040.     if (hasColor) {
  3041.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  3042.     }
  3043.     XCopyArea (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXWindow,
  3044.                Nlm_currentXGC, srcX, srcY, width, height, dstX, dstY);
  3045.     XSync (Nlm_currentXDisplay, FALSE);
  3046.     while (XCheckTypedWindowEvent (Nlm_currentXDisplay,
  3047.            Nlm_currentXWindow, GraphicsExpose, &event)) {
  3048.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3049.                   event.xgraphicsexpose.x, event.xgraphicsexpose.y,
  3050.                   event.xgraphicsexpose.width, event.xgraphicsexpose.height,
  3051.                   TRUE);
  3052.     }
  3053.     if (dx > 0) {
  3054.       rct = *r;
  3055.       rct.right = rct.left + dx;
  3056.       Nlm_RecTToRectTool (&rct, &rtool);
  3057.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3058.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3059.                   rtool.width, rtool.height, TRUE);
  3060.     } else if (dx < 0) {
  3061.       rct = *r;
  3062.       rct.left = rct.right + dx;
  3063.       Nlm_RecTToRectTool (&rct, &rtool);
  3064.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3065.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3066.                   rtool.width, rtool.height, TRUE);
  3067.     }
  3068.     if (dy > 0) {
  3069.       rct = *r;
  3070.       rct.bottom = rct.top + dy;
  3071.       Nlm_RecTToRectTool (&rct, &rtool);
  3072.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3073.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3074.                   rtool.width, rtool.height, TRUE);
  3075.     } else if (dy < 0) {
  3076.       rct = *r;
  3077.       rct.top = rct.bottom + dy;
  3078.       Nlm_RecTToRectTool (&rct, &rtool);
  3079.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3080.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3081.                   rtool.width, rtool.height, TRUE);
  3082.     }
  3083.     if (hasColor) {
  3084.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentFgColor);
  3085.     }
  3086.   }
  3087. #endif
  3088. }
  3089.  
  3090. extern void Nlm_EraseOval (Nlm_RectPtr r)
  3091.  
  3092. {
  3093. #ifdef WIN_MAC
  3094.   Nlm_RectTool  rtool;
  3095.  
  3096.   if (r != NULL) {
  3097.     Nlm_RecTToRectTool (r, &rtool);
  3098.     EraseOval (&rtool);
  3099.   }
  3100. #endif
  3101. #ifdef WIN_MSWIN
  3102.   HBRUSH  oldBrush;
  3103.   HPEN    oldPen;
  3104.  
  3105.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  3106.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3107.     oldBrush = SelectObject (Nlm_currentHDC, GetBackgroundBrush (Nlm_currentHWnd));
  3108.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3109.     if (oldPen != NULL) {
  3110.       SelectObject (Nlm_currentHDC, oldPen);
  3111.     }
  3112.     if (oldBrush != NULL) {
  3113.       SelectObject (Nlm_currentHDC, oldBrush);
  3114.     }
  3115.   }
  3116. #endif
  3117. #ifdef WIN_X
  3118. #endif
  3119. }
  3120.  
  3121. extern void Nlm_FrameOval (Nlm_RectPtr r)
  3122.  
  3123. {
  3124. #ifdef WIN_MAC
  3125.   Nlm_RectTool  rtool;
  3126.  
  3127.   if (r != NULL) {
  3128.     Nlm_RecTToRectTool (r, &rtool);
  3129.     FrameOval (&rtool);
  3130.   }
  3131. #endif
  3132. #ifdef WIN_MSWIN
  3133.   HBRUSH  oldBrush;
  3134.  
  3135.   if (r != NULL && Nlm_currentHDC != NULL) {
  3136.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (NULL_BRUSH));
  3137.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3138.     if (oldBrush != NULL) {
  3139.       SelectObject (Nlm_currentHDC, oldBrush);
  3140.     }
  3141.   }
  3142. #endif
  3143. #ifdef WIN_X
  3144.   Nlm_RectTool  rtool;
  3145.  
  3146.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3147.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3148.     Nlm_RecTToRectTool (r, &rtool);
  3149.     XDrawArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3150.               rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3151.               rtool.width - 1, rtool.height - 1, 0, 23040);
  3152.   }
  3153. #endif
  3154. }
  3155.  
  3156. extern void Nlm_PaintOval (Nlm_RectPtr r)
  3157.  
  3158. {
  3159. #ifdef WIN_MAC
  3160.   Nlm_RectTool  rtool;
  3161.  
  3162.   if (r != NULL) {
  3163.     Nlm_RecTToRectTool (r, &rtool);
  3164.     PaintOval (&rtool);
  3165.   }
  3166. #endif
  3167. #ifdef WIN_MSWIN
  3168.   HPEN  oldPen;
  3169.  
  3170.   if (r != NULL && Nlm_currentHDC != NULL) {
  3171.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3172.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3173.     if (oldPen != NULL) {
  3174.       SelectObject (Nlm_currentHDC, oldPen);
  3175.     }
  3176.   }
  3177. #endif
  3178. #ifdef WIN_X
  3179.   Nlm_RectTool  rtool;
  3180.  
  3181.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3182.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3183.     Nlm_RecTToRectTool (r, &rtool);
  3184.     XFillArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3185.               rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3186.               rtool.width, rtool.height, 0, 23040);
  3187.   }
  3188. #endif
  3189. }
  3190.  
  3191. extern void Nlm_InvertOval (Nlm_RectPtr r)
  3192.  
  3193. {
  3194. #ifdef WIN_MAC
  3195.   Nlm_RectTool  rtool;
  3196.  
  3197.   if (r != NULL) {
  3198.     Nlm_RecTToRectTool (r, &rtool);
  3199.     InvertOval (&rtool);
  3200.   }
  3201. #endif
  3202. #ifdef WIN_MSWIN
  3203.   HBRUSH    oldBrush;
  3204.   Nlm_Int2  oldMode;
  3205.   HPEN      oldPen;
  3206.  
  3207.   if (r != NULL && Nlm_currentHDC != NULL) {
  3208.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  3209.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  3210.     oldMode = GetROP2 (Nlm_currentHDC);
  3211.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  3212.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3213.     if (oldPen != NULL) {
  3214.       SelectObject (Nlm_currentHDC, oldPen);
  3215.     }
  3216.     if (oldBrush != NULL) {
  3217.       SelectObject (Nlm_currentHDC, oldBrush);
  3218.     }
  3219.     SetROP2 (Nlm_currentHDC, oldMode);
  3220.   }
  3221. #endif
  3222. #ifdef WIN_X
  3223. #endif
  3224. }
  3225.  
  3226. extern void Nlm_EraseRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3227.                                 Nlm_Int2 ovlHgt)
  3228.  
  3229. {
  3230. #ifdef WIN_MAC
  3231.   Nlm_RectTool  rtool;
  3232.  
  3233.   if (r != NULL) {
  3234.     Nlm_RecTToRectTool (r, &rtool);
  3235.     EraseRoundRect (&rtool, ovlWid, ovlHgt);
  3236.   }
  3237. #endif
  3238. #ifdef WIN_MSWIN
  3239.   HBRUSH  oldBrush;
  3240.   HPEN    oldPen;
  3241.  
  3242.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  3243.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3244.     oldBrush = SelectObject (Nlm_currentHDC, GetBackgroundBrush (Nlm_currentHWnd));
  3245.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3246.     if (oldPen != NULL) {
  3247.       SelectObject (Nlm_currentHDC, oldPen);
  3248.     }
  3249.     if (oldBrush != NULL) {
  3250.       SelectObject (Nlm_currentHDC, oldBrush);
  3251.     }
  3252.   }
  3253. #endif
  3254. #ifdef WIN_X
  3255. #endif
  3256. }
  3257.  
  3258. extern void Nlm_FrameRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3259.                                 Nlm_Int2 ovlHgt)
  3260.  
  3261. {
  3262. #ifdef WIN_MAC
  3263.   Nlm_RectTool  rtool;
  3264.  
  3265.   if (r != NULL) {
  3266.     Nlm_RecTToRectTool (r, &rtool);
  3267.     FrameRoundRect (&rtool, ovlWid, ovlHgt);
  3268.   }
  3269. #endif
  3270. #ifdef WIN_MSWIN
  3271.   HBRUSH  oldBrush;
  3272.  
  3273.   if (r != NULL && Nlm_currentHDC != NULL) {
  3274.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (NULL_BRUSH));
  3275.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3276.     if (oldBrush != NULL) {
  3277.       SelectObject (Nlm_currentHDC, oldBrush);
  3278.     }
  3279.   }
  3280. #endif
  3281. #ifdef WIN_X
  3282. #endif
  3283. }
  3284.  
  3285. extern void Nlm_PaintRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3286.                                 Nlm_Int2 ovlHgt)
  3287.  
  3288. {
  3289. #ifdef WIN_MAC
  3290.   Nlm_RectTool  rtool;
  3291.  
  3292.   if (r != NULL) {
  3293.     Nlm_RecTToRectTool (r, &rtool);
  3294.     PaintRoundRect (&rtool, ovlWid, ovlHgt);
  3295.   }
  3296. #endif
  3297. #ifdef WIN_MSWIN
  3298.   HPEN  oldPen;
  3299.  
  3300.   if (r != NULL && Nlm_currentHDC != NULL) {
  3301.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3302.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3303.     if (oldPen != NULL) {
  3304.       SelectObject (Nlm_currentHDC, oldPen);
  3305.     }
  3306.   }
  3307. #endif
  3308. #ifdef WIN_X
  3309. #endif
  3310. }
  3311.  
  3312. extern void Nlm_InvertRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3313.                                  Nlm_Int2 ovlHgt)
  3314.  
  3315. {
  3316. #ifdef WIN_MAC
  3317.   Nlm_RectTool  rtool;
  3318.  
  3319.   if (r != NULL) {
  3320.     Nlm_RecTToRectTool (r, &rtool);
  3321.     InvertRoundRect (&rtool, ovlWid, ovlHgt);
  3322.   }
  3323. #endif
  3324. #ifdef WIN_MSWIN
  3325.   HBRUSH    oldBrush;
  3326.   Nlm_Int2  oldMode;
  3327.   HPEN      oldPen;
  3328.  
  3329.   if (r != NULL && Nlm_currentHDC != NULL) {
  3330.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  3331.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  3332.     oldMode = GetROP2 (Nlm_currentHDC);
  3333.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  3334.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3335.     if (oldPen != NULL) {
  3336.       SelectObject (Nlm_currentHDC, oldPen);
  3337.     }
  3338.     if (oldBrush != NULL) {
  3339.       SelectObject (Nlm_currentHDC, oldBrush);
  3340.     }
  3341.     SetROP2 (Nlm_currentHDC, oldMode);
  3342.   }
  3343. #endif
  3344. #ifdef WIN_X
  3345. #endif
  3346. }
  3347.  
  3348. #ifdef WIN_X
  3349. static int Nlm_PtToAngle (Nlm_RectPtr r, Nlm_PoinT pt)
  3350.  
  3351. {
  3352.   int     rsult;
  3353.   double  val;
  3354.   double  x;
  3355.   double  y;
  3356.  
  3357.   x = pt.x - (r->right + r->left) / 2;
  3358.   y = (r->bottom + r->top) / 2 - pt.y;
  3359.   if (x == 0) {
  3360.     rsult = 5760;
  3361.   } else if (y == 0) {
  3362.     rsult = 0;
  3363.   } else {
  3364.     val = atan2 (ABS (y), ABS (x));
  3365.     rsult = val * 11520.0 / 3.14159;
  3366.   }
  3367.   if (x < 0) {
  3368.     if (y < 0) {
  3369.       rsult = 11520 + rsult;
  3370.     } else {
  3371.       rsult = 11520 - rsult;
  3372.     }
  3373.   } else if (y < 0) {
  3374.     rsult = 23040 - rsult;
  3375.   }
  3376.   return rsult;
  3377. }
  3378. #endif
  3379.  
  3380. extern void Nlm_EraseArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3381.  
  3382. {
  3383. #ifdef WIN_MAC
  3384.   Nlm_Int2       angle1;
  3385.   Nlm_Int2       angle2;
  3386.   Nlm_Int2       arcAngle;
  3387.   Nlm_PointTool  ptool1;
  3388.   Nlm_PointTool  ptool2;
  3389.   Nlm_RectTool   rtool;
  3390.  
  3391.   if (r != NULL) {
  3392.     Nlm_RecTToRectTool (r, &rtool);
  3393.     Nlm_PoinTToPointTool (start, &ptool1);
  3394.     Nlm_PoinTToPointTool (end, &ptool2);
  3395.     PtToAngle (&rtool, ptool1, &angle1);
  3396.     PtToAngle (&rtool, ptool2, &angle2);
  3397.     if (angle2 > angle1) {
  3398.       arcAngle = angle2 - angle1;
  3399.     } else {
  3400.       arcAngle = 360 - angle1 + angle2;
  3401.     }
  3402.     EraseArc (&rtool, angle1, arcAngle);
  3403.   }
  3404. #endif
  3405. #ifdef WIN_MSWIN
  3406.   HBRUSH  oldBrush;
  3407.   HPEN    oldPen;
  3408.  
  3409.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  3410.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3411.     oldBrush = SelectObject (Nlm_currentHDC, GetBackgroundBrush (Nlm_currentHWnd));
  3412.     Pie (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3413.          end.x, end.y, start.x, start.y);
  3414.     if (oldPen != NULL) {
  3415.       SelectObject (Nlm_currentHDC, oldPen);
  3416.     }
  3417.     if (oldBrush != NULL) {
  3418.       SelectObject (Nlm_currentHDC, oldBrush);
  3419.     }
  3420.   }
  3421. #endif
  3422. #ifdef WIN_X
  3423. #endif
  3424. }
  3425.  
  3426. extern void Nlm_FrameArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3427. {
  3428. #ifdef WIN_MAC
  3429.   Nlm_Int2       angle1;
  3430.   Nlm_Int2       angle2;
  3431.   Nlm_Int2       arcAngle;
  3432.   Nlm_PointTool  ptool1;
  3433.   Nlm_PointTool  ptool2;
  3434.   Nlm_RectTool   rtool;
  3435.  
  3436.   if (r != NULL) {
  3437.     Nlm_RecTToRectTool (r, &rtool);
  3438.     Nlm_PoinTToPointTool (start, &ptool1);
  3439.     Nlm_PoinTToPointTool (end, &ptool2);
  3440.     PtToAngle (&rtool, ptool1, &angle1);
  3441.     PtToAngle (&rtool, ptool2, &angle2);
  3442.     if (angle2 > angle1) {
  3443.       arcAngle = angle2 - angle1;
  3444.     } else {
  3445.       arcAngle = 360 - angle1 + angle2;
  3446.     }
  3447.     FrameArc (&rtool, angle1, arcAngle);
  3448.   }
  3449. #endif
  3450. #ifdef WIN_MSWIN
  3451.   HPEN  oldPen;
  3452.  
  3453.   if (r != NULL && Nlm_currentHDC != NULL) {
  3454.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3455.     Arc (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3456.          end.x, end.y, start.x, start.y);
  3457.     if (oldPen != NULL) {
  3458.       SelectObject (Nlm_currentHDC, oldPen);
  3459.     }
  3460.   }
  3461. #endif
  3462. #ifdef WIN_X
  3463.   int           angle1;
  3464.   int           angle2;
  3465.   int           arcAngle;
  3466.   Nlm_RectTool  rtool;
  3467.  
  3468.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3469.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3470.     Nlm_RecTToRectTool (r, &rtool);
  3471.     angle1 = Nlm_PtToAngle (r, start);
  3472.     angle2 = Nlm_PtToAngle (r, end);
  3473.     if (angle1 > angle2) {
  3474.       arcAngle = angle1 - angle2;
  3475.       XDrawArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3476.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3477.                 rtool.width - 1, rtool.height - 1, angle1, -arcAngle);
  3478.     } else {
  3479.       arcAngle = 23040 - angle2 + angle1;
  3480.       XDrawArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3481.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3482.                 rtool.width - 1, rtool.height - 1, angle1, -arcAngle);
  3483.     }
  3484.   }
  3485. #endif
  3486. }
  3487.  
  3488. extern void Nlm_PaintArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3489.  
  3490. {
  3491. #ifdef WIN_MAC
  3492.   Nlm_Int2       angle1;
  3493.   Nlm_Int2       angle2;
  3494.   Nlm_Int2       arcAngle;
  3495.   Nlm_PointTool  ptool1;
  3496.   Nlm_PointTool  ptool2;
  3497.   Nlm_RectTool   rtool;
  3498.  
  3499.   if (r != NULL) {
  3500.     Nlm_RecTToRectTool (r, &rtool);
  3501.     Nlm_PoinTToPointTool (start, &ptool1);
  3502.     Nlm_PoinTToPointTool (end, &ptool2);
  3503.     PtToAngle (&rtool, ptool1, &angle1);
  3504.     PtToAngle (&rtool, ptool2, &angle2);
  3505.     if (angle2 > angle1) {
  3506.       arcAngle = angle2 - angle1;
  3507.     } else {
  3508.       arcAngle = 360 - angle1 + angle2;
  3509.     }
  3510.     PaintArc (&rtool, angle1, arcAngle);
  3511.   }
  3512. #endif
  3513. #ifdef WIN_MSWIN
  3514.   HPEN  oldPen;
  3515.  
  3516.   if (r != NULL && Nlm_currentHDC != NULL) {
  3517.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3518.     Pie (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3519.          end.x, end.y, start.x, start.y);
  3520.     if (oldPen != NULL) {
  3521.       SelectObject (Nlm_currentHDC, oldPen);
  3522.     }
  3523.   }
  3524. #endif
  3525. #ifdef WIN_X
  3526.   int           angle1;
  3527.   int           angle2;
  3528.   int           arcAngle;
  3529.   Nlm_RectTool  rtool;
  3530.  
  3531.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3532.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3533.     Nlm_RecTToRectTool (r, &rtool);
  3534.     angle1 = Nlm_PtToAngle (r, start);
  3535.     angle2 = Nlm_PtToAngle (r, end);
  3536.     if (angle1 > angle2) {
  3537.       arcAngle = angle1 - angle2;
  3538.       XFillArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3539.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3540.                 rtool.width, rtool.height, angle1, -arcAngle);
  3541.     } else {
  3542.       arcAngle = 23040 - angle2 + angle1;
  3543.       XFillArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3544.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3545.                 rtool.width, rtool.height, angle1, -arcAngle);
  3546.     }
  3547.   }
  3548. #endif
  3549. }
  3550.  
  3551. extern void Nlm_InvertArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3552.  
  3553. {
  3554. #ifdef WIN_MAC
  3555.   Nlm_Int2       angle1;
  3556.   Nlm_Int2       angle2;
  3557.   Nlm_Int2       arcAngle;
  3558.   Nlm_PointTool  ptool1;
  3559.   Nlm_PointTool  ptool2;
  3560.   Nlm_RectTool   rtool;
  3561.  
  3562.   if (r != NULL) {
  3563.     Nlm_RecTToRectTool (r, &rtool);
  3564.     Nlm_PoinTToPointTool (start, &ptool1);
  3565.     Nlm_PoinTToPointTool (end, &ptool2);
  3566.     PtToAngle (&rtool, ptool1, &angle1);
  3567.     PtToAngle (&rtool, ptool2, &angle2);
  3568.     if (angle2 > angle1) {
  3569.       arcAngle = angle2 - angle1;
  3570.     } else {
  3571.       arcAngle = 360 - angle1 + angle2;
  3572.     }
  3573.     InvertArc (&rtool, angle1, arcAngle);
  3574.   }
  3575. #endif
  3576. #ifdef WIN_MSWIN
  3577.   HBRUSH    oldBrush;
  3578.   Nlm_Int2  oldMode;
  3579.   HPEN      oldPen;
  3580.  
  3581.   if (r != NULL && Nlm_currentHDC != NULL) {
  3582.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  3583.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  3584.     oldMode = GetROP2 (Nlm_currentHDC);
  3585.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  3586.     Pie (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3587.          end.x, end.y, start.x, start.y);
  3588.     if (oldPen != NULL) {
  3589.       SelectObject (Nlm_currentHDC, oldPen);
  3590.     }
  3591.     if (oldBrush != NULL) {
  3592.       SelectObject (Nlm_currentHDC, oldBrush);
  3593.     }
  3594.     SetROP2 (Nlm_currentHDC, oldMode);
  3595.   }
  3596. #endif
  3597. #ifdef WIN_X
  3598. #endif
  3599. }
  3600.  
  3601. #ifdef WIN_MAC
  3602. static PolyHandle Nlm_CreatePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3603.  
  3604. {
  3605.   Nlm_PoinT   firstPt;
  3606.   Nlm_Int2    i;
  3607.   Nlm_PoinT   pt;
  3608.   PolyHandle  rsult;
  3609.  
  3610.   rsult = NULL;
  3611.   if (pts != NULL && num > 0) {
  3612.     rsult = OpenPoly ();
  3613.     firstPt = pts [0];
  3614.     MoveTo (firstPt.x, firstPt.y);
  3615.     for (i = 1; i < num; i++) {
  3616.       pt = pts [i];
  3617.       LineTo (pt.x, pt.y);
  3618.     }
  3619.     if (! Nlm_EqualPt (pt, firstPt)) {
  3620.       LineTo (firstPt.x, firstPt.y);
  3621.     }
  3622.     ClosePoly ();
  3623.   }
  3624.   return rsult;
  3625. }
  3626.  
  3627. static void Nlm_DestroyPoly (PolyHandle ply)
  3628.  
  3629. {
  3630.   if (ply != NULL) {
  3631.     KillPoly (ply);
  3632.   }
  3633. }
  3634. #endif
  3635.  
  3636. #ifdef WIN_MSWIN
  3637. static LPPOINT Nlm_CreatePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3638.  
  3639. {
  3640.   Nlm_PoinT      firstPt;
  3641.   Nlm_Int2       i;
  3642.   Nlm_PoinT      pt;
  3643.   Nlm_PointTool  ptool;
  3644.   LPPOINT        rsult;
  3645.  
  3646.   rsult = NULL;
  3647.   if (pts != NULL && num > 0) {
  3648.     rsult = (LPPOINT) Nlm_MemNew ((Nlm_sizeT) ((num + 1) * sizeof (POINT)));
  3649.     if (rsult != NULL) {
  3650.       firstPt = pts [0];
  3651.       for (i = 0; i < num; i++) {
  3652.         pt = pts [i];
  3653.         Nlm_PoinTToPointTool (pt, &ptool);
  3654.         rsult [i] = ptool;
  3655.       }
  3656.       if (! Nlm_EqualPt (pt, firstPt)) {
  3657.         Nlm_PoinTToPointTool (firstPt, &ptool);
  3658.         rsult [i] = ptool;
  3659.       }
  3660.     }
  3661.   }
  3662.   return rsult;
  3663. }
  3664.  
  3665. static void Nlm_DestroyPoly (LPPOINT ply)
  3666.  
  3667. {
  3668.   if (ply != NULL) {
  3669.     Nlm_MemFree (ply);
  3670.   }
  3671. }
  3672. #endif
  3673.  
  3674. #ifdef WIN_X
  3675. static XPoint *Nlm_CreatePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3676.  
  3677. {
  3678.   Nlm_PoinT      firstPt;
  3679.   Nlm_Int2       i;
  3680.   Nlm_PoinT      pt;
  3681.   Nlm_PointTool  ptool;
  3682.   XPoint         *rsult;
  3683.  
  3684.   rsult = NULL;
  3685.   if (pts != NULL && num > 0) {
  3686.     rsult = (XPoint *) Nlm_MemNew ((Nlm_sizeT) ((num + 1) * sizeof (XPoint)));
  3687.     if (rsult != NULL) {
  3688.       firstPt = pts [0];
  3689.       firstPt.x -= Nlm_XOffset;
  3690.       firstPt.y -= Nlm_YOffset;
  3691.       for (i = 0; i < num; i++) {
  3692.         pt = pts [i];
  3693.         pt.x -= Nlm_XOffset;
  3694.         pt.y -= Nlm_YOffset;
  3695.         Nlm_PoinTToPointTool (pt, &ptool);
  3696.         rsult [i] = ptool;
  3697.       }
  3698.       if (! Nlm_EqualPt (pt, firstPt)) {
  3699.         Nlm_PoinTToPointTool (firstPt, &ptool);
  3700.         rsult [i] = ptool;
  3701.       }
  3702.     }
  3703.   }
  3704.   return rsult;
  3705. }
  3706.  
  3707. static void Nlm_DestroyPoly (XPoint *ply)
  3708.  
  3709. {
  3710.   if (ply != NULL) {
  3711.     Nlm_MemFree (ply);
  3712.   }
  3713. }
  3714. #endif
  3715.  
  3716. extern void Nlm_ErasePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3717.  
  3718. {
  3719.   if (pts != NULL && num > 1) {
  3720. #ifdef WIN_MAC
  3721.   PolyHandle   ply;
  3722.  
  3723.   ply = Nlm_CreatePoly (num, pts);
  3724.   if (ply != NULL) {
  3725.     ErasePoly (ply);
  3726.   }
  3727.   Nlm_DestroyPoly (ply);
  3728. #endif
  3729. #ifdef WIN_MSWIN
  3730. #endif
  3731. #ifdef WIN_X
  3732. #endif
  3733.   }
  3734. }
  3735.  
  3736. extern void Nlm_FramePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3737.  
  3738. {
  3739.   if (pts != NULL && num > 1) {
  3740. #ifdef WIN_MAC
  3741.   PolyHandle   ply;
  3742.  
  3743.   ply = Nlm_CreatePoly (num, pts);
  3744.   if (ply != NULL) {
  3745.     FramePoly (ply);
  3746.   }
  3747.   Nlm_DestroyPoly (ply);
  3748. #endif
  3749. #ifdef WIN_MSWIN
  3750.   LPPOINT  ply;
  3751.  
  3752.   ply = Nlm_CreatePoly (num, pts);
  3753.   if (Nlm_currentHDC != NULL && ply != NULL) {
  3754.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3755.       num++;
  3756.     }
  3757.     Polyline (Nlm_currentHDC, ply, num);
  3758.   }
  3759.   Nlm_DestroyPoly (ply);
  3760. #endif
  3761. #ifdef WIN_X
  3762.   XPoint  *ply;
  3763.  
  3764.   ply = Nlm_CreatePoly (num, pts);
  3765.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  3766.       Nlm_currentXGC != NULL && ply != NULL) {
  3767.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3768.       num++;
  3769.     }
  3770.     XDrawLines (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3771.                 ply, num, CoordModeOrigin);
  3772.   }
  3773.   Nlm_DestroyPoly (ply);
  3774. #endif
  3775.   }
  3776. }
  3777.  
  3778. extern void Nlm_PaintPoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3779.  
  3780. {
  3781.   if (pts != NULL && num > 1) {
  3782. #ifdef WIN_MAC
  3783.   PolyHandle   ply;
  3784.  
  3785.   ply = Nlm_CreatePoly (num, pts);
  3786.   if (ply != NULL) {
  3787.     PaintPoly (ply);
  3788.   }
  3789.   Nlm_DestroyPoly (ply);
  3790. #endif
  3791. #ifdef WIN_MSWIN
  3792.   LPPOINT  ply;
  3793.  
  3794.   ply = Nlm_CreatePoly (num, pts);
  3795.   if (Nlm_currentHDC != NULL && ply != NULL) {
  3796.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3797.       num++;
  3798.     }
  3799.     SetPolyFillMode (Nlm_currentHDC, ALTERNATE);
  3800.     Polygon (Nlm_currentHDC, ply, num);
  3801.   }
  3802.   Nlm_DestroyPoly (ply);
  3803. #endif
  3804. #ifdef WIN_X
  3805.   XPoint  *ply;
  3806.  
  3807.   ply = Nlm_CreatePoly (num, pts);
  3808.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  3809.       Nlm_currentXGC != NULL && ply != NULL) {
  3810.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3811.       num++;
  3812.     }
  3813.     XSetFillRule (Nlm_currentXDisplay, Nlm_currentXGC, EvenOddRule);
  3814.     XFillPolygon (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3815.                   ply, num, Complex, CoordModeOrigin);
  3816.   }
  3817.   Nlm_DestroyPoly (ply);
  3818. #endif
  3819.   }
  3820. }
  3821.  
  3822. extern void Nlm_InvertPoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3823.  
  3824. {
  3825.   if (pts != NULL && num > 1) {
  3826. #ifdef WIN_MAC
  3827.   PolyHandle   ply;
  3828.  
  3829.   ply = Nlm_CreatePoly (num, pts);
  3830.   if (ply != NULL) {
  3831.     InvertPoly (ply);
  3832.   }
  3833.   Nlm_DestroyPoly (ply);
  3834. #endif
  3835. #ifdef WIN_MSWIN
  3836. #endif
  3837. #ifdef WIN_X
  3838. #endif
  3839.   }
  3840. }
  3841.  
  3842. extern Nlm_RegioN Nlm_CreateRgn (void)
  3843.  
  3844. {
  3845.   Nlm_RgnTool  ntool;
  3846.  
  3847. #ifdef WIN_MAC
  3848.   ntool = NewRgn ();
  3849. #endif
  3850. #ifdef WIN_MSWIN
  3851.   ntool = CreateRectRgn (0, 0, 0, 0);
  3852. #endif
  3853. #ifdef WIN_X
  3854.   ntool = XCreateRegion ();
  3855. #endif
  3856.   return (Nlm_RegioN) ntool;
  3857. }
  3858.  
  3859. extern Nlm_RegioN Nlm_DestroyRgn (Nlm_RegioN rgn)
  3860.  
  3861. {
  3862.   Nlm_RgnTool  ntool;
  3863.  
  3864.   if (rgn != NULL) {
  3865.     ntool = (Nlm_RgnTool) rgn;
  3866. #ifdef WIN_MAC
  3867.     DisposeRgn (ntool);
  3868. #endif
  3869. #ifdef WIN_MSWIN
  3870.     DeleteObject (ntool);
  3871. #endif
  3872. #ifdef WIN_X
  3873.     XDestroyRegion (ntool);
  3874. #endif
  3875.   }
  3876.   return NULL;
  3877. }
  3878.  
  3879. extern void Nlm_ClearRgn (Nlm_RegioN rgn)
  3880.  
  3881. {
  3882.   Nlm_RgnTool  ntool;
  3883.   Nlm_RgnTool  temp;
  3884.  
  3885.   if (rgn != NULL) {
  3886.     ntool = (Nlm_RgnTool) rgn;
  3887. #ifdef WIN_MAC
  3888.     SetEmptyRgn (ntool);
  3889. #endif
  3890. #ifdef WIN_MSWIN
  3891.     temp = CreateRectRgn (0, 0, 0, 0);
  3892.     CombineRgn (ntool, temp, temp, RGN_COPY);
  3893.     DeleteObject (temp);
  3894. #endif
  3895. #ifdef WIN_X
  3896.     XUnionRegion (emptyRgn, emptyRgn, ntool);
  3897. #endif
  3898.   } 
  3899. }
  3900.  
  3901. extern void Nlm_LoadRectRgn (Nlm_RegioN rgn, Nlm_Int2 lf,
  3902.                              Nlm_Int2 tp, Nlm_Int2 rt,
  3903.                              Nlm_Int2 bt)
  3904.  
  3905. {
  3906.   Nlm_RgnTool   ntool;
  3907. #ifdef WIN_X
  3908.   Nlm_RecT      rct;
  3909.   Nlm_RectTool  rtool;
  3910. #endif
  3911.  
  3912.   if (rgn != NULL) {
  3913.     ntool = (Nlm_RgnTool) rgn;
  3914. #ifdef WIN_MAC
  3915.     SetRectRgn (ntool, lf, tp, rt, bt);
  3916. #endif
  3917. #ifdef WIN_MSWIN
  3918.     SetRectRgn (ntool, lf, tp, rt, bt);
  3919. #endif
  3920. #ifdef WIN_X
  3921.     Nlm_LoadRect (&rct, lf, tp, rt, bt);
  3922.     Nlm_RecTToRectTool (&rct, &rtool);
  3923.     XUnionRectWithRegion (&rtool, emptyRgn, ntool);
  3924. #endif
  3925.   }
  3926. }
  3927.  
  3928. extern void Nlm_OffsetRgn (Nlm_RegioN rgn, Nlm_Int2 dx, Nlm_Int2 dy)
  3929.  
  3930. {
  3931.   Nlm_RgnTool  ntool;
  3932.  
  3933.   if (rgn != NULL) {
  3934.     ntool = (Nlm_RgnTool) rgn;
  3935. #ifdef WIN_MAC
  3936.     OffsetRgn (ntool, dx, dy);
  3937. #endif
  3938. #ifdef WIN_MSWIN
  3939.     OffsetRgn (ntool, dx, dy);
  3940. #endif
  3941. #ifdef WIN_X
  3942.     XOffsetRegion (ntool, dx, dy);
  3943. #endif
  3944.   }
  3945. }
  3946.  
  3947. extern void Nlm_SectRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  3948.  
  3949. {
  3950.   Nlm_RgnTool  ntool1;
  3951.   Nlm_RgnTool  ntool2;
  3952.   Nlm_RgnTool  ntool3;
  3953. #ifdef WIN_X
  3954.   Nlm_RgnTool  temp;
  3955. #endif
  3956.  
  3957.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  3958.     ntool1 = (Nlm_RgnTool) src1;
  3959.     ntool2 = (Nlm_RgnTool) src2;
  3960.     ntool3 = (Nlm_RgnTool) dst;
  3961. #ifdef WIN_MAC
  3962.     SectRgn (ntool1, ntool2, ntool3);
  3963. #endif
  3964. #ifdef WIN_MSWIN
  3965.     CombineRgn (ntool3, ntool1, ntool2, RGN_AND);
  3966. #endif
  3967. #ifdef WIN_X
  3968.     temp = XCreateRegion ();
  3969.     XIntersectRegion (ntool1, ntool2, temp);
  3970.     XUnionRegion (temp, emptyRgn, ntool3);
  3971.     XDestroyRegion (temp);
  3972. #endif
  3973.   }
  3974. }
  3975.  
  3976. extern void Nlm_UnionRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  3977.  
  3978. {
  3979.   Nlm_RgnTool  ntool1;
  3980.   Nlm_RgnTool  ntool2;
  3981.   Nlm_RgnTool  ntool3;
  3982. #ifdef WIN_X
  3983.   Nlm_RgnTool  temp;
  3984. #endif
  3985.  
  3986.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  3987.     ntool1 = (Nlm_RgnTool) src1;
  3988.     ntool2 = (Nlm_RgnTool) src2;
  3989.     ntool3 = (Nlm_RgnTool) dst;
  3990. #ifdef WIN_MAC
  3991.     UnionRgn (ntool1, ntool2, ntool3);
  3992. #endif
  3993. #ifdef WIN_MSWIN
  3994.     CombineRgn (ntool3, ntool1, ntool2, RGN_OR);
  3995. #endif
  3996. #ifdef WIN_X
  3997.     temp = XCreateRegion ();
  3998.     XUnionRegion (ntool1, ntool2, temp);
  3999.     XUnionRegion (temp, emptyRgn, ntool3);
  4000.     XDestroyRegion (temp);
  4001. #endif
  4002.   }
  4003. }
  4004.  
  4005. extern void Nlm_DiffRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  4006.  
  4007. {
  4008.   Nlm_RgnTool  ntool1;
  4009.   Nlm_RgnTool  ntool2;
  4010.   Nlm_RgnTool  ntool3;
  4011. #ifdef WIN_X
  4012.   Nlm_RgnTool  temp;
  4013. #endif
  4014.  
  4015.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  4016.     ntool1 = (Nlm_RgnTool) src1;
  4017.     ntool2 = (Nlm_RgnTool) src2;
  4018.     ntool3 = (Nlm_RgnTool) dst;
  4019. #ifdef WIN_MAC
  4020.     DiffRgn (ntool1, ntool2, ntool3);
  4021. #endif
  4022. #ifdef WIN_MSWIN
  4023.     CombineRgn (ntool3, ntool1, ntool2, RGN_DIFF);
  4024. #endif
  4025. #ifdef WIN_X
  4026.     temp = XCreateRegion ();
  4027.     XSubtractRegion (ntool1, ntool2, temp);
  4028.     XUnionRegion (temp, emptyRgn, ntool3);
  4029.     XDestroyRegion (temp);
  4030. #endif
  4031.   }
  4032. }
  4033.  
  4034. extern void Nlm_XorRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  4035.  
  4036. {
  4037.   Nlm_RgnTool  ntool1;
  4038.   Nlm_RgnTool  ntool2;
  4039.   Nlm_RgnTool  ntool3;
  4040. #ifdef WIN_X
  4041.   Nlm_RgnTool  temp;
  4042. #endif
  4043.  
  4044.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  4045.     ntool1 = (Nlm_RgnTool) src1;
  4046.     ntool2 = (Nlm_RgnTool) src2;
  4047.     ntool3 = (Nlm_RgnTool) dst;
  4048. #ifdef WIN_MAC
  4049.     XorRgn (ntool1, ntool2, ntool3);
  4050. #endif
  4051. #ifdef WIN_MSWIN
  4052.     CombineRgn (ntool3, ntool1, ntool2, RGN_XOR);
  4053. #endif
  4054. #ifdef WIN_X
  4055.     temp = XCreateRegion ();
  4056.     XXorRegion (ntool1, ntool2, temp);
  4057.     XUnionRegion (temp, emptyRgn, ntool3);
  4058.     XDestroyRegion (temp);
  4059. #endif
  4060.   }
  4061. }
  4062.  
  4063. extern Nlm_Boolean Nlm_EqualRgn (Nlm_RegioN rgn1, Nlm_RegioN rgn2)
  4064.  
  4065. {
  4066.   Nlm_RgnTool  ntool1;
  4067.   Nlm_RgnTool  ntool2;
  4068.   Nlm_Boolean  rsult;
  4069.  
  4070.   rsult = FALSE;
  4071.   if (rgn1 != NULL && rgn2 != NULL) {
  4072.     ntool1 = (Nlm_RgnTool) rgn1;
  4073.     ntool2 = (Nlm_RgnTool) rgn2;
  4074. #ifdef WIN_MAC
  4075.     rsult = EqualRgn (ntool1, ntool2);
  4076. #endif
  4077. #ifdef WIN_MSWIN
  4078.     rsult = (Nlm_Boolean) EqualRgn (ntool1, ntool2);
  4079. #endif
  4080. #ifdef WIN_X
  4081.     rsult = (XEqualRegion (ntool1, ntool2) != 0);
  4082. #endif
  4083.   }
  4084.   return rsult;
  4085. }
  4086.  
  4087. extern Nlm_Boolean Nlm_EmptyRgn (Nlm_RegioN rgn)
  4088.  
  4089. {
  4090.   Nlm_RgnTool   ntool;
  4091.   Nlm_Boolean   rsult;
  4092. #ifdef WIN_MSWIN
  4093.   Nlm_RectTool  rtool;
  4094. #endif
  4095.  
  4096.   rsult = FALSE;
  4097.   if (rgn != NULL) {
  4098.     ntool = (Nlm_RgnTool) rgn;
  4099. #ifdef WIN_MAC
  4100.     rsult = EmptyRgn (ntool);
  4101. #endif
  4102. #ifdef WIN_MSWIN
  4103.     rsult = (Nlm_Boolean) (GetRgnBox (ntool, &rtool) == NULLREGION);
  4104. #endif
  4105. #ifdef WIN_X
  4106.     rsult = (XEmptyRegion (ntool) != 0);
  4107. #endif
  4108.   }
  4109.   return rsult;
  4110. }
  4111.  
  4112. extern void Nlm_EraseRgn (Nlm_RegioN rgn)
  4113.  
  4114. {
  4115. #ifdef WIN_MAC
  4116.   Nlm_RgnTool  ntool;
  4117.  
  4118.   if (rgn != NULL) {
  4119.     ntool = (Nlm_RgnTool) rgn;
  4120.     EraseRgn (ntool);
  4121.   }
  4122. #endif
  4123. #ifdef WIN_MSWIN
  4124.   Nlm_RgnTool  ntool;
  4125.  
  4126.   if (rgn != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  4127.     ntool = (Nlm_RgnTool) rgn;
  4128.     FillRgn (Nlm_currentHDC, ntool, GetBackgroundBrush (Nlm_currentHWnd));
  4129.   }
  4130. #endif
  4131. #ifdef WIN_X
  4132. #endif
  4133. }
  4134.  
  4135. extern void Nlm_FrameRgn (Nlm_RegioN rgn)
  4136.  
  4137. {
  4138. #ifdef WIN_MAC
  4139.   Nlm_RgnTool  ntool;
  4140.  
  4141.   if (rgn != NULL) {
  4142.     ntool = (Nlm_RgnTool) rgn;
  4143.     FrameRgn (ntool);
  4144.   }
  4145. #endif
  4146. #ifdef WIN_MSWIN
  4147.   Nlm_RgnTool  ntool;
  4148.  
  4149.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4150.     ntool = (Nlm_RgnTool) rgn;
  4151.     FrameRgn (Nlm_currentHDC, ntool, GetStockObject (BLACK_BRUSH), 1, 1);
  4152.   }
  4153. #endif
  4154. #ifdef WIN_X
  4155. #endif
  4156. }
  4157.  
  4158. extern void Nlm_PaintRgn (Nlm_RegioN rgn)
  4159.  
  4160. {
  4161. #ifdef WIN_MAC
  4162.   Nlm_RgnTool  ntool;
  4163.  
  4164.   if (rgn != NULL) {
  4165.     ntool = (Nlm_RgnTool) rgn;
  4166.     PaintRgn (ntool);
  4167.   }
  4168. #endif
  4169. #ifdef WIN_MSWIN
  4170.   Nlm_RgnTool  ntool;
  4171.   HBRUSH       oldBrush;
  4172.  
  4173.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4174.     ntool = (Nlm_RgnTool) rgn;
  4175.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  4176.     if (oldBrush != NULL) {
  4177.       SelectObject (Nlm_currentHDC, oldBrush);
  4178.       FillRgn (Nlm_currentHDC, ntool, oldBrush);
  4179.     }
  4180.   }
  4181. #endif
  4182. #ifdef WIN_X
  4183. #endif
  4184. }
  4185.  
  4186. extern void Nlm_InvertRgn (Nlm_RegioN rgn)
  4187.  
  4188. {
  4189. #ifdef WIN_MAC
  4190.   Nlm_RgnTool  ntool;
  4191.  
  4192.   if (rgn != NULL) {
  4193.     ntool = (Nlm_RgnTool) rgn;
  4194.     InvertRgn (ntool);
  4195.   }
  4196. #endif
  4197. #ifdef WIN_MSWIN
  4198.   Nlm_RgnTool  ntool;
  4199.  
  4200.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4201.     ntool = (Nlm_RgnTool) rgn;
  4202.     InvertRgn (Nlm_currentHDC, ntool);
  4203.   }
  4204. #endif
  4205. #ifdef WIN_X
  4206. #endif
  4207. }
  4208.  
  4209. extern void Nlm_ClipRect (Nlm_RectPtr r)
  4210.  
  4211. {
  4212. #ifdef WIN_MAC
  4213.   Nlm_RectTool  rtool;
  4214.  
  4215.   if (r != NULL) {
  4216.     Nlm_RecTToRectTool (r, &rtool);
  4217.     ClipRect (&rtool);
  4218.   }
  4219. #endif
  4220. #ifdef WIN_MSWIN
  4221.   HRGN  hRgnClip;
  4222.  
  4223.   if (r != NULL && Nlm_currentHDC != NULL) {
  4224.     hRgnClip = CreateRectRgn (r->left, r->top, r->right, r->bottom);
  4225.     SelectClipRgn (Nlm_currentHDC, hRgnClip);
  4226.     DeleteObject (hRgnClip);
  4227.   }
  4228. #endif
  4229. #ifdef WIN_X
  4230.   Nlm_RectTool  rtool;
  4231.  
  4232.   if (r != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  4233.     Nlm_RecTToRectTool (r, &rtool);
  4234.     rtool.x -= Nlm_XOffset;
  4235.     rtool.y -= Nlm_YOffset;
  4236.     XSetClipRectangles (Nlm_currentXDisplay, Nlm_currentXGC, 0, 0, &rtool, 1, Unsorted);
  4237.     if (Nlm_clpRgn != NULL) {
  4238.       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
  4239.       Nlm_clpRgn = NULL;
  4240.     }
  4241.     Nlm_clpRgn = (Nlm_RegioN) XCreateRegion ();
  4242.     XUnionRectWithRegion (&rtool, (Nlm_RgnTool) Nlm_clpRgn, (Nlm_RgnTool) Nlm_clpRgn);
  4243.     XOffsetRegion ((Nlm_RgnTool) Nlm_clpRgn, Nlm_XOffset, Nlm_YOffset);
  4244.   }
  4245. #endif
  4246. }
  4247.  
  4248. extern void Nlm_ClipRgn (Nlm_RegioN rgn)
  4249.  
  4250. {
  4251. #ifdef WIN_MAC
  4252.   Nlm_RgnTool  ntool;
  4253.  
  4254.   if (rgn != NULL) {
  4255.     ntool = (Nlm_RgnTool) rgn;
  4256.     SetClip (ntool);
  4257.   }
  4258. #endif
  4259. #ifdef WIN_MSWIN
  4260.   Nlm_RgnTool  ntool;
  4261.  
  4262.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4263.     ntool = (Nlm_RgnTool) rgn;
  4264.     SelectClipRgn (Nlm_currentHDC, ntool);
  4265.   }
  4266. #endif
  4267. #ifdef WIN_X
  4268.   Nlm_RgnTool  ntool1;
  4269.   Nlm_RgnTool  ntool2;
  4270.  
  4271.   if (rgn != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  4272.     ntool1 = XCreateRegion ();
  4273.     ntool2 = XCreateRegion ();
  4274.     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, ntool2);
  4275.     XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
  4276.     XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
  4277.     if (Nlm_clpRgn != NULL) {
  4278.       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
  4279.       Nlm_clpRgn = NULL;
  4280.     }
  4281.     Nlm_clpRgn = (Nlm_RegioN) XCreateRegion ();
  4282.     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, (Nlm_RgnTool) Nlm_clpRgn);
  4283.     XOffsetRegion ((Nlm_RgnTool) Nlm_clpRgn, -Nlm_XOffset, -Nlm_YOffset);
  4284.     XDestroyRegion (ntool1);
  4285.     XDestroyRegion (ntool2);
  4286.   }
  4287. #endif
  4288. }
  4289.  
  4290. extern void Nlm_ResetClip (void)
  4291.  
  4292. {
  4293. #ifdef WIN_MAC
  4294.   Nlm_RecT      r;
  4295.   Nlm_RectTool  rtool;
  4296.  
  4297.   Nlm_LoadRect (&r, -32767, -32767, 32767, 32767);
  4298.   Nlm_RecTToRectTool (&r, &rtool);
  4299.   ClipRect (&rtool);
  4300. #endif
  4301. #ifdef WIN_MSWIN
  4302.   if (Nlm_currentHDC != NULL) {
  4303.     SelectClipRgn (Nlm_currentHDC, NULL);
  4304.   }
  4305. #endif
  4306. #ifdef WIN_X
  4307.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  4308.     XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  4309.     if (Nlm_clpRgn != NULL) {
  4310.       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
  4311.       Nlm_clpRgn = NULL;
  4312.     }
  4313.   }
  4314. #endif
  4315. }
  4316.  
  4317. extern void Nlm_ValidRect (Nlm_RectPtr r)
  4318.  
  4319. {
  4320. #ifdef WIN_MAC
  4321.   Nlm_RectTool  rtool;
  4322.  
  4323.   if (r != NULL) {
  4324.     Nlm_RecTToRectTool (r, &rtool);
  4325.     ValidRect (&rtool);
  4326.   }
  4327. #endif
  4328. #ifdef WIN_MSWIN
  4329.   Nlm_RectTool  rtool;
  4330.  
  4331.   if (r != NULL && Nlm_currentHWnd != NULL) {
  4332.     Nlm_RecTToRectTool (r, &rtool);
  4333.     ValidateRect (Nlm_currentHWnd, &rtool);
  4334.   }
  4335. #endif
  4336. #ifdef WIN_X
  4337. #endif
  4338. }
  4339.  
  4340. extern void Nlm_InvalRect (Nlm_RectPtr r)
  4341.  
  4342. {
  4343. #ifdef WIN_MAC
  4344.   Nlm_RectTool  rtool;
  4345.  
  4346.   if (r != NULL) {
  4347.     Nlm_RecTToRectTool (r, &rtool);
  4348.     InvalRect (&rtool);
  4349.   }
  4350. #endif
  4351. #ifdef WIN_MSWIN
  4352.   Nlm_RectTool  rtool;
  4353.  
  4354.   if (r != NULL && Nlm_currentHWnd != NULL) {
  4355.     Nlm_RecTToRectTool (r, &rtool);
  4356.     InvalidateRect (Nlm_currentHWnd, &rtool, TRUE);
  4357.   }
  4358. #endif
  4359. #ifdef WIN_X
  4360.   Nlm_RectTool  rtool;
  4361.  
  4362.   if (r != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0) {
  4363.     Nlm_RecTToRectTool (r, &rtool);
  4364.     XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  4365.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  4366.                 rtool.width, rtool.height, TRUE);
  4367.   }
  4368. #endif
  4369. }
  4370.  
  4371. extern void Nlm_ValidRgn (Nlm_RegioN rgn)
  4372.  
  4373. {
  4374. #ifdef WIN_MAC
  4375.   if (rgn != NULL) {
  4376.     ValidRgn ((Nlm_RgnTool) rgn);
  4377.   }
  4378. #endif
  4379. #ifdef WIN_MSWIN
  4380.   if (rgn != NULL && Nlm_currentHWnd != NULL) {
  4381.     ValidateRgn (Nlm_currentHWnd, (Nlm_RgnTool) rgn);
  4382.   }
  4383. #endif
  4384. #ifdef WIN_X
  4385. #endif
  4386. }
  4387.  
  4388. extern void Nlm_InvalRgn (Nlm_RegioN rgn)
  4389.  
  4390. {
  4391. #ifdef WIN_MAC
  4392.   if (rgn != NULL) {
  4393.     InvalRgn ((Nlm_RgnTool) rgn);
  4394.   }
  4395. #endif
  4396. #ifdef WIN_MSWIN
  4397.   if (rgn != NULL && Nlm_currentHWnd != NULL) {
  4398.     InvalidateRgn (Nlm_currentHWnd, (Nlm_RgnTool) rgn, TRUE);
  4399.   }
  4400. #endif
  4401. #ifdef WIN_X
  4402.   Nlm_RgnTool   ntool1;
  4403.   Nlm_RgnTool   ntool2;
  4404.   Nlm_RectTool  rtool;
  4405.  
  4406.   if (rgn != NULL && Nlm_currentXDisplay != NULL &&
  4407.       Nlm_currentXGC != NULL && Nlm_currentXWindow != 0) {
  4408.     ntool1 = XCreateRegion ();
  4409.     ntool2 = XCreateRegion ();
  4410.     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, ntool2);
  4411.     XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
  4412.     XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
  4413.     XClipBox (ntool2, &rtool);
  4414.     XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow, rtool.x,
  4415.                 rtool.y, rtool.width, rtool.height, TRUE);
  4416.     XDestroyRegion (ntool1);
  4417.     XDestroyRegion (ntool2);
  4418.     if (Nlm_clpRgn != NULL) {
  4419.       ntool1 = XCreateRegion ();
  4420.       ntool2 = XCreateRegion ();
  4421.       XUnionRegion ((Nlm_RgnTool) Nlm_clpRgn, ntool1, ntool2);
  4422.       XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
  4423.       XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
  4424.       XDestroyRegion (ntool1);
  4425.       XDestroyRegion (ntool2);
  4426.     } else {
  4427.       XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  4428.     }
  4429.   }
  4430. #endif
  4431. }
  4432.  
  4433. extern void Nlm_CopyBits (Nlm_RectPtr r, Nlm_VoidPtr source)
  4434.  
  4435. {
  4436. #ifdef WIN_MAC
  4437.   BitMap    dstBits;
  4438.   Nlm_Int2  mode;
  4439.   PenState  pnState;
  4440.   GrafPtr   port;
  4441.   Rect      rect;
  4442.   BitMap    srcBits;
  4443.   Rect      srcRect;
  4444.  
  4445.   if (r != NULL && source != NULL) {
  4446.     GetPort (&port);
  4447.     GetPenState (&pnState);
  4448.     switch (pnState.pnMode) {
  4449.       case patCopy:
  4450.         mode = srcCopy;
  4451.         break;
  4452.       case patOr:
  4453.         mode = srcOr;
  4454.         break;
  4455.       case patXor:
  4456.         mode = srcXor;
  4457.         break;
  4458.       case patBic:
  4459.         mode = srcBic;
  4460.         break;
  4461.       default:
  4462.         mode = srcCopy;
  4463.         break;
  4464.     }
  4465.     Nlm_RecTToRectTool (r, &rect);
  4466.     srcRect = rect;
  4467.     OffsetRect (&srcRect, -rect.left, -rect.top);
  4468.     srcBits.baseAddr = (Ptr) source;
  4469.     srcBits.rowBytes = (rect.right - rect.left - 1) / 8 + 1;
  4470.     srcBits.bounds = srcRect;
  4471.     dstBits = port->portBits;
  4472.     CopyBits (&srcBits, &dstBits, &srcRect, &rect, mode, NULL);
  4473.   }
  4474. #endif
  4475. #ifdef WIN_MSWIN
  4476.   Nlm_Int2      cols;
  4477.   HBITMAP       hBitmap;
  4478.   HBITMAP       hOldBitmap;
  4479.   HDC           hMemoryDC;
  4480.   Nlm_Int2      i;
  4481.   Nlm_Int2      j;
  4482.   Nlm_Int4      mode;
  4483.   Nlm_Int4      num;
  4484.   Nlm_Boolean   odd;
  4485.   Nlm_Uint1Ptr  p;
  4486.   Nlm_Uint1Ptr  ptr;
  4487.   Nlm_Uint1Ptr  q;
  4488.   Nlm_Int2      rop2;
  4489.   Nlm_Int2      rows;
  4490.  
  4491.   if (r != NULL && source != NULL && Nlm_currentHDC != NULL) {
  4492.     rows = (r->right - r->left - 1) / 8 + 1;
  4493.     odd = (Nlm_Boolean) ((rows & 1) != 0);
  4494.     cols = r->bottom - r->top;
  4495.     num = rows * cols;
  4496.     if (odd) {
  4497.       num += cols;
  4498.     }
  4499.     ptr = (Nlm_Uint1Ptr) Nlm_MemNew ((Nlm_sizeT) num * sizeof (Nlm_Uint1));
  4500.     if (ptr != NULL) {
  4501.       p = source;
  4502.       q = ptr;
  4503.       for (i = 0; i < cols; i++) {
  4504.         j = 0;
  4505.         while (j < rows) {
  4506.           *q = *p;
  4507.           p++;
  4508.           q++;
  4509.           j++;
  4510.         }
  4511.         if (odd) {
  4512.           *q = 0;
  4513.           q++;
  4514.         }
  4515.       }
  4516.       q = ptr;
  4517.       while (num > 0) {
  4518.         *q = (Nlm_Uint1) ~(*q);
  4519.         q++;
  4520.         num--;
  4521.       }
  4522.       hBitmap = CreateBitmap (r->right - r->left, r->bottom - r->top,
  4523.                               1, 1, (LPSTR) ptr);
  4524.       hMemoryDC = CreateCompatibleDC (Nlm_currentHDC);
  4525.       hOldBitmap = SelectObject (hMemoryDC, hBitmap);
  4526.       if (hOldBitmap != NULL) {
  4527.         rop2 = GetROP2 (Nlm_currentHDC);
  4528.         switch (rop2) {
  4529.           case R2_COPYPEN:
  4530.             mode = SRCCOPY;
  4531.             break;
  4532.           case R2_MASKPEN:
  4533.             mode = SRCAND;
  4534.             break;
  4535.           case R2_NOTXORPEN:
  4536.             mode = 0x00990066;
  4537.             break;
  4538.           case R2_MERGENOTPEN:
  4539.             mode = MERGEPAINT;
  4540.             break;
  4541.           default:
  4542.             mode = WHITENESS;
  4543.             break;
  4544.         }
  4545.         BitBlt (Nlm_currentHDC, r->left, r->top,
  4546.                 r->right - r->left, r->bottom - r->top,
  4547.                 hMemoryDC, 0, 0, mode);
  4548.         SelectObject (hMemoryDC, hOldBitmap);
  4549.       }
  4550.       Nlm_MemFree (ptr);
  4551.       DeleteDC (hMemoryDC);
  4552.       DeleteObject (hBitmap);
  4553.     }
  4554.   }
  4555. #endif
  4556. #ifdef WIN_X
  4557.   Nlm_Int2      cols;
  4558.   Nlm_Int2      height;
  4559.   Nlm_Int2      i;
  4560.   Nlm_Int2      j;
  4561.   Nlm_Int4      num;
  4562.   Pixmap        pixmap;
  4563.   Nlm_Uint1Ptr  ptr;
  4564.   Nlm_Uint1Ptr  q;
  4565.   Nlm_Int2      rows;
  4566.   Nlm_Int2      width;
  4567.  
  4568.   if (r != NULL && source != NULL && Nlm_currentXDisplay != NULL &&
  4569.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  4570.     rows = (r->right - r->left - 1) / 8 + 1;
  4571.     cols = r->bottom - r->top;
  4572.     num = rows * cols;
  4573.     ptr = (Nlm_Uint1Ptr) Nlm_MemNew ((Nlm_sizeT) num * sizeof (Nlm_Uint1));
  4574.     if (ptr != NULL) {
  4575.       Nlm_MemCopy (ptr, source, (Nlm_sizeT) num);
  4576.       q = ptr;
  4577.       while (num > 0) {
  4578.         *q = flip [*q];
  4579.         q++;
  4580.         num--;
  4581.       }
  4582.       width = r->right - r->left;
  4583.       height = r->bottom - r->top;
  4584.       pixmap = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  4585.                                       (char *) ptr, width, height);
  4586.       if (currentMode != MERGE_MODE) {
  4587.         XCopyPlane (Nlm_currentXDisplay, pixmap, Nlm_currentXWindow,
  4588.                     Nlm_currentXGC, 0, 0, width, height,
  4589.                     r->left - Nlm_XOffset, r->top - Nlm_YOffset, 1);
  4590.       } else {
  4591.         XSetClipOrigin (Nlm_currentXDisplay, Nlm_currentXGC,
  4592.                         r->left - Nlm_XOffset, r->top - Nlm_YOffset);
  4593.         XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, pixmap);
  4594.         XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXcopy);
  4595.         XCopyPlane (Nlm_currentXDisplay, pixmap, Nlm_currentXWindow,
  4596.                     Nlm_currentXGC, 0, 0, width, height,
  4597.                     r->left - Nlm_XOffset, r->top - Nlm_YOffset, 1);
  4598.         XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXand);
  4599.         XSetClipOrigin (Nlm_currentXDisplay, Nlm_currentXGC, 0, 0);
  4600.         if (Nlm_clpRgn != NULL) {
  4601.           XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, (Nlm_RgnTool) Nlm_clpRgn);
  4602.         } else {
  4603.           XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  4604.         }
  4605.       }
  4606.       XFreePixmap (Nlm_currentXDisplay, pixmap);
  4607.       Nlm_MemFree (ptr);
  4608.     }
  4609.   }
  4610. #endif
  4611. }
  4612.  
  4613. #ifdef WIN_X
  4614. static Nlm_Uint4 Nlm_SetupColor (Colormap colormap, Nlm_Int2 red, Nlm_Int2 green, Nlm_Int2 blue)
  4615.  
  4616. {
  4617.   XColor  xcolor;
  4618.  
  4619.   xcolor.red = red << 8;
  4620.   xcolor.green = green << 8;
  4621.   xcolor.blue = blue << 8;
  4622.   if (XAllocColor (Nlm_currentXDisplay, colormap, &xcolor) == 0) {
  4623.     xcolor.pixel = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4624.   }
  4625.   return xcolor.pixel;
  4626. }
  4627. #endif
  4628.  
  4629. extern void Nlm_SetUpDrawingTools (void)
  4630.  
  4631. {
  4632. #ifdef WIN_MAC
  4633.   RgnPtr     rptr;
  4634.   SysEnvRec  sysenv;
  4635.  
  4636.   Nlm_scrollRgn = (Nlm_RegioN) (NewRgn ());
  4637.  
  4638.   Nlm_updateRgn = (Nlm_RegioN) (NewRgn ());
  4639.   SetRectRgn ((Nlm_RgnTool) Nlm_updateRgn, -32768, -32768, 32767, 32767);
  4640.   HLock ((Handle) Nlm_updateRgn);
  4641.   rptr = (RgnPtr) *((Handle) Nlm_updateRgn);
  4642.   Nlm_RectToolToRecT (&(rptr->rgnBBox), &Nlm_updateRect);
  4643.   HUnlock ((Handle) Nlm_updateRgn);
  4644.  
  4645.   Nlm_fontList = NULL;
  4646.   Nlm_fontInUse = NULL;
  4647.   Nlm_systemFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4648.   Nlm_LoadFontData (Nlm_systemFont, NULL, "", 12, 0, FALSE,
  4649.                     FALSE, FALSE, 0, 0, NULL, NULL);
  4650.   Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4651.   Nlm_LoadFontData (Nlm_programFont, NULL, "", 9, 0, FALSE,
  4652.                     FALSE, FALSE, 4, 0, NULL, NULL);
  4653.   Nlm_fontList = NULL;
  4654.   Nlm_fontInUse = Nlm_systemFont;
  4655.  
  4656.   Nlm_stdAscent = Nlm_Ascent ();
  4657.   Nlm_stdDescent = Nlm_Descent ();
  4658.   Nlm_stdLeading = Nlm_Leading ();
  4659.   Nlm_stdFontHeight = Nlm_FontHeight ();
  4660.   Nlm_stdLineHeight = Nlm_LineHeight ();
  4661.   Nlm_stdCharWidth = Nlm_MaxCharWidth ();
  4662.   SysEnvirons (1, &sysenv);
  4663.   hasColorQD = sysenv.hasColorQD;
  4664.   if (hasColorQD) {
  4665.     Nlm_RGBforeColor.red = 0;
  4666.     Nlm_RGBforeColor.green = 0;
  4667.     Nlm_RGBforeColor.blue = 0;
  4668.     Nlm_RGBbackColor.red = 65535;
  4669.     Nlm_RGBbackColor.green = 65535;
  4670.     Nlm_RGBbackColor.blue = 65535;
  4671.   }
  4672. #endif
  4673. #ifdef WIN_MSWIN
  4674.   Nlm_RectTool  rtool;
  4675.  
  4676.   Nlm_scrollRgn = (Nlm_RegioN) (CreateRectRgn (0, 0, 0, 0));
  4677.  
  4678.   Nlm_updateRgn = (Nlm_RegioN) (CreateRectRgn (-32767, -32767, 32767, 32767));
  4679.   GetRgnBox ((Nlm_RgnTool) Nlm_updateRgn, &rtool);
  4680.   Nlm_RectToolToRecT (&rtool, &Nlm_updateRect);
  4681.  
  4682.   Nlm_fontList = NULL;
  4683.   Nlm_fontInUse = NULL;
  4684.   Nlm_systemFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4685.   Nlm_LoadFontData (Nlm_systemFont, NULL, "", 0, 0, FALSE, FALSE, FALSE,
  4686.                     0, 0, GetStockObject (SYSTEM_FONT), NULL);
  4687.   Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4688.   Nlm_LoadFontData (Nlm_programFont, NULL, "", 0, 0, FALSE, FALSE, FALSE,
  4689.                     0, 0, GetStockObject (ANSI_FIXED_FONT), NULL);
  4690.   Nlm_fontList = NULL;
  4691.   Nlm_fontInUse = Nlm_systemFont;
  4692.  
  4693.   Nlm_stdAscent = Nlm_Ascent ();
  4694.   Nlm_stdDescent = Nlm_Descent ();
  4695.   Nlm_stdLeading = Nlm_Leading ();
  4696.   Nlm_stdFontHeight = Nlm_FontHeight ();
  4697.   Nlm_stdLineHeight = Nlm_LineHeight ();
  4698.   Nlm_stdCharWidth = Nlm_MaxCharWidth ();
  4699.  
  4700.   blackColor = RGB (0, 0, 0);
  4701.   redColor = RGB (255, 0, 0);
  4702.   greenColor = RGB (0, 255, 0);
  4703.   blueColor = RGB (0, 0, 255);
  4704.   cyanColor = RGB (0, 255, 255);
  4705.   magentaColor = RGB (255, 0, 255);
  4706.   yellowColor = RGB (255, 255, 0);
  4707.   whiteColor = RGB (255, 255, 255);
  4708.  
  4709.   hBlackPen = GetStockObject (BLACK_PEN);
  4710.   hNullPen = GetStockObject (NULL_PEN);
  4711.   hWhitePen = GetStockObject (WHITE_PEN);
  4712.   hBlackBrush = GetStockObject (BLACK_BRUSH);
  4713.   hDkGrayBrush = GetStockObject (DKGRAY_BRUSH);
  4714.   hGrayBrush = GetStockObject (GRAY_BRUSH);
  4715.   hHollowBrush = GetStockObject (HOLLOW_BRUSH);
  4716.   hLtGrayBrush = GetStockObject (LTGRAY_BRUSH);
  4717.   hNullBrush = GetStockObject (NULL_BRUSH);
  4718.   hWhiteBrush = GetStockObject (WHITE_BRUSH);
  4719.   hAnsiFixedFont = GetStockObject (ANSI_FIXED_FONT);
  4720.   hAnsiVarFont = GetStockObject (ANSI_VAR_FONT);
  4721.   hDeviceDefaultFont = GetStockObject (DEVICE_DEFAULT_FONT);
  4722.   hOemFixedFont = GetStockObject (OEM_FIXED_FONT);
  4723.   hSystemFont = GetStockObject (SYSTEM_FONT);
  4724.   hSystemFixedFont = GetStockObject (SYSTEM_FIXED_FONT);
  4725. #endif
  4726. #ifdef WIN_X
  4727.   Colormap      colormap;
  4728.   XFontStruct   *f;
  4729.   Nlm_Int2      i;
  4730.   Nlm_Uint2     inv;
  4731.   Nlm_Int2      j;
  4732.   XFontStruct   *p;
  4733.   Nlm_RecT      r;
  4734.   Nlm_RectTool  rtool;
  4735.   Nlm_Uint2     val;
  4736.  
  4737.   Nlm_scrollRgn = (Nlm_RegioN) (XCreateRegion ());
  4738.  
  4739.   Nlm_updateRgn = (Nlm_RegioN) (XCreateRegion ());
  4740.   Nlm_LoadRect (&r, -32767, -32767, 32767, 32767);
  4741.   Nlm_RecTToRectTool (&r, &rtool);
  4742.   XUnionRectWithRegion (&rtool, (Nlm_RgnTool) Nlm_updateRgn, (Nlm_RgnTool) Nlm_updateRgn);
  4743.   Nlm_RectToolToRecT (&rtool, &Nlm_updateRect);
  4744.  
  4745.   emptyRgn = XCreateRegion ();
  4746.  
  4747.   Nlm_fontList = NULL;
  4748.   Nlm_fontInUse = NULL;
  4749.   f = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-helvetica-bold-r-*--14-*", TRUE);
  4750.   Nlm_systemFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4751.   Nlm_LoadFontData (Nlm_systemFont, NULL, "", 12, 0, FALSE,
  4752.                     FALSE, FALSE, 0, 0, f, NULL);
  4753.   p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-fixed-medium-r-*--13-*", FALSE);
  4754.   if (p == NULL) {
  4755.     p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-courier-medium-r-*--12-*", FALSE);
  4756.   }
  4757.   if (p == NULL) {
  4758.     p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "8x13", FALSE);
  4759.   }
  4760.   if (p == NULL) {
  4761.     p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "9x15", TRUE);
  4762.   }
  4763.   Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4764.   Nlm_LoadFontData (Nlm_programFont, NULL, "", 9, 0, FALSE,
  4765.                     FALSE, FALSE, 4, 0, p, NULL);
  4766.   Nlm_fontList = NULL;
  4767.   Nlm_fontInUse = Nlm_systemFont;
  4768.  
  4769.   XSetFont (Nlm_currentXDisplay, Nlm_currentXGC, f->fid);
  4770.   currentFont = f;
  4771.   Nlm_stdAscent = Nlm_Ascent ();
  4772.   Nlm_stdDescent = Nlm_Descent ();
  4773.   Nlm_stdLeading = Nlm_Leading ();
  4774.   Nlm_stdFontHeight = Nlm_FontHeight ();
  4775.   Nlm_stdLineHeight = Nlm_LineHeight ();
  4776.   Nlm_stdCharWidth = Nlm_MaxCharWidth ();
  4777.  
  4778.   hasColor = FALSE;
  4779.   if (Nlm_currentXDisplay != NULL) {
  4780.     hasColor = (XDisplayCells (Nlm_currentXDisplay, Nlm_currentXScreen) > 2);
  4781.     if (hasColor) {
  4782.       colormap = DefaultColormap (Nlm_currentXDisplay, Nlm_currentXScreen);
  4783.       whiteColor = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4784.       blackColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4785.       redColor = Nlm_SetupColor (colormap, 255, 0, 0);
  4786.       greenColor = Nlm_SetupColor (colormap, 0, 255, 0);
  4787.       blueColor = Nlm_SetupColor (colormap, 0, 0, 255);
  4788.       cyanColor = Nlm_SetupColor (colormap, 0, 255, 255);
  4789.       magentaColor = Nlm_SetupColor (colormap, 255, 0, 255);
  4790.       yellowColor = Nlm_SetupColor (colormap, 255, 255, 0);
  4791.     } else {
  4792.       whiteColor = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4793.       blackColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4794.       redColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4795.       greenColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4796.       blueColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4797.       cyanColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4798.       magentaColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4799.       yellowColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4800.     }
  4801.   }
  4802.   fontInfo.fid = 0;
  4803.   for (i = 0; i < 256; i++) {
  4804.     inv = 0;
  4805.     val = (Nlm_Uint2) i;
  4806.     for (j = 0; j < 8; j++) {
  4807.       inv = (inv << 1);
  4808.       inv += (val % 2);
  4809.       val = (val >> 1);
  4810.     }
  4811.     flip [i] = inv;
  4812.   }
  4813.  
  4814.   Nlm_XbackColor = whiteColor;
  4815.   Nlm_XforeColor = blackColor;
  4816.   Nlm_XOffset = 0;
  4817.   Nlm_YOffset = 0;
  4818.   Nlm_clpRgn = NULL;
  4819. #endif
  4820. }
  4821.  
  4822. extern void Nlm_CleanUpDrawingTools (void)
  4823.  
  4824. {
  4825.   Nlm_FonT      f;
  4826.   Nlm_FontData  fdata;
  4827.  
  4828.   Nlm_ResetDrawingTools ();
  4829. #ifdef WIN_MOTIF
  4830.   Nlm_GetFontData (Nlm_systemFont, &fdata);
  4831.   if (fdata.handle != NULL) {
  4832.     XFreeFont (Nlm_currentXDisplay, fdata.handle);
  4833.   }
  4834.   Nlm_GetFontData (Nlm_programFont, &fdata);
  4835.   if (fdata.handle != NULL) {
  4836.     XFreeFont (Nlm_currentXDisplay, fdata.handle);
  4837.   }
  4838. #endif
  4839.   Nlm_HandFree (Nlm_systemFont);
  4840.   Nlm_HandFree (Nlm_programFont);
  4841.   f = Nlm_fontList;
  4842.   while (f != NULL) {
  4843.     Nlm_GetFontData (f, &fdata);
  4844. #ifdef WIN_MSWIN
  4845.     if (fdata.handle != NULL) {
  4846.       DeleteObject (fdata.handle);
  4847.     }
  4848. #endif
  4849. #ifdef WIN_MOTIF
  4850.     if (fdata.handle != NULL) {
  4851.       XFreeFont (Nlm_currentXDisplay, fdata.handle);
  4852.     }
  4853. #endif
  4854.     Nlm_HandFree (f);
  4855.     f = fdata.next;
  4856.   }
  4857. #ifdef WIN_MOTIF
  4858.   XDestroyRegion (emptyRgn);
  4859. #endif
  4860. }
  4861.